COE518 Lecture Notes Week 4 (Sept. 26, 2011)

Size: px
Start display at page:

Download "COE518 Lecture Notes Week 4 (Sept. 26, 2011)"

Transcription

1 coe518 (Operating Systems) Lecture Notes: Week 4 Page 1 of 11 COE518 Lecture Notes Week 4 (Sept. 26, 2011) Topics Why fork(), then exec()? The delta list structure Alternative approach to Lab 2 More on processes More or threads Amdahl's Law Textbook sections Stallings (7 th edition): Chapter 4.3 (Multicore and multithreading) Tanenbaum (3 rd edition): Chapters 2.1 (Processes), 2.2 (Threads), 4.3 (Multicore and multithreading) Announcements Quiz: Wednesday October 12, 2011 Midterm: Wednesday October 26, 2011 Why fork() then exec()? Forking has been described as creating an exact clone of a process (that invoked the fork()) by copying all its program and data areas into newly allocated ones for the newly created child process. Typically, the child process then almost immediately overlays all of these memory areas with

2 coe518 (Operating Systems) Lecture Notes: Week 4 Page 2 of 11 new content for a totally different process that is exec'ed. This seems ridiculous! Some clarification: The copying is more conceptual than real. For example, the program area is usually read-only and can be safely shared amongst different processes. Similarly, the data area is usually small and the child often only needs read-access to it. (Memory management hardware can be used to permit safe read-only access to the child process. If the child does perform a write, the hardware would detect this and the OS would then make a physical copy of part or all of the memory segment for the child. The child does need its own stack but is unlikely to need write access far down. So while the copying of data is conceptually accurate, the actual overhead is quite small. And the advantages of the child having access to its parent's knowledge are considerable. This is particularly clear when writing a shell program. The code below illustrates how output redirection is parsed by the shell and then implemented by the child. Some things to know when examining the code: The OS maintains an array of file descriptos for each process. Element zero is stdin, fd[1] is stdout and fd[2] is stderr. Redirecting stdout to a file rather than the default terminal is done with dup2(somefd,1) #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <sys/wait.h> #include <sys/types.h> #include <sys/stat.h> #include <string.h> int main(int argc, char * argv[], char **envp) { pid_t child; char * myargv[] = {NULL, NULL, NULL, NULL; char * stdout_redirect = "";//Default:stdout not redirected int status; /* Hard coded demo code: Assumes user typed: * ls -l > junk

3 coe518 (Operating Systems) Lecture Notes: Week 4 Page 3 of 11 * Such would be parsed to set up myargv as * shown below. The ">" (redirection symbol) * would be parsed by the shell and the * word following it ("junk") * would be recognized as the file stdout should * be redirected to. The redirection * is then implemented by the child. */ myargv[0] = "ls"; myargv[1] = "-l"; stdout_redirect = "./junk"; /* End of demo code */ child = fork(); if (child == 0) { if (strcmp("", stdout_redirect)!= 0) { //child changes stdout file //by redefining fd[1]. int stdout_now = open("./junk", O_CREAT O_WRONLY O_TRUNC, 0666); dup2(stdout_now, 1); execvp(myargv[0], myargv); return EXIT_FAILURE; wait(&status); fprintf(stderr, "Parent of %d\n", child); return EXIT_SUCCESS; The Delta List A delta list is an efficient data structure for maintaining a list (of arbitrary length) of events scheduled for some future time. Tine flows disretely by ticks; one tick could be a millisecond, a second, a minute or whatever the application requires. The key of the first item on the list is the number of ticks remaining before the event is scheduled to occur. The first item on the list describes the event that will be first one to be triggered. The key for the second item is the number of ticks it should wait after the first item is triggered.

4 coe518 (Operating Systems) Lecture Notes: Week 4 Page 4 of 11 Similarly, the key for the third item is the number of ticks after the second item. At each tick, the key for the first item on the list is decremented. If it reaches zero, it is removed from the list and the action indicated is triggered. If after removing it, the new head of the list has a key of zero, it is also removed and triggered. This continues until the head of the list has a non-zero key. Example: Suppose there are 3 future events. Event A is scheduled to be triggered in 2 ticks from now ; Event B in 3 ticks; and Event C in 7 ticks. The delta list would look something like: Key Event 2 A 1 B 4 C After one tick, we have: Key Event 1 A 1 B 4 C After two ticks, we have: Key Event 0 A 1 B 4 C Since the key is zero, Event A is deleted and triggered. Key Event 1 B

5 coe518 (Operating Systems) Lecture Notes: Week 4 Page 5 of 11 4 C After 3 ticks, Event B's key is zero and it is deleted and triggered. Key Event 4 C After 4 more ticks (a total of 7), Event C is removed and triggered. New events can be inserted at any time. For example, suppose that after one tick with the previous example we want to insert a new Event D that should occur 3 ticks from now Key Event 1 A 1 B 1 D 3 C An alternative approach to Lab 2 The suggested approach to Lab 2 is: Collect the entire line into a buffer (an array of chars). Parse the buffer to identify each word; determine its length, use malloc(...) to allocate enough memory for it (string length + 1), copy the word to it and make myargv[i] (where i is 0 for the first word, 1 for the second, etc) point to the allocated memory. An advantage of this approach is that it is composed of several smallish steps and gives you experience with malloc(). There is an alternative approach which is somewhat more elegant and more efficient; the disadtage is that it is all one step and yuo have to get it all right. The alternative approach is:

6 coe518 (Operating Systems) Lecture Notes: Week 4 Page 6 of 11 Set myargv[0] to the first non-white character you get from stdin and place in the buffer. Continue reading character by charcter, copying into the buffer until you hit whitespace. Then place '\0' in the buffer until you encounter a non-whitespace character. That is the start of the myargv[1] pointer. Continue till you get the end of line character. More about processes A process consists of: 1. A program area in memory containing the machine language instructions of the process. 2. A data area in memory which can be separated into 3 components: i. Space for the runtime stack. ii. Space for global variables. iii. Space for a heap for dynamically allocated memory. (The size of the heap can also be increased with an OS call.) 3. A Process Control Block (PCB) which contains: i. Process state: Running, Ready (ready to run), or Blocked (waiting for something). When a process is blocked, it cannot continue running until some event occurs. For example, it could be waiting for I/O, for some time to elapse (usleep()), for some interprocess communication (IPC), for its child to die (wait()), etc. ii. Process ID Number (PID): A unique identifier for the process. iii. Owner (or User): On a multi-user system, the user who initiated the process. (When a user logs off, all processes owned by him or her are usually terminated.)q iv. CPU state: The values of all CPU registers the last time the process was running (or the initial values if the process has not yet run.) v. Memory areas: Description (starting address and size) of the memory segments used by the process. vi. Parent ID (PPID): PID of the parent process. vii. Statistics: How much time the CPU has been used (both user and supervisor modes). viii. Priority: Used by the scheduling algorithm to select a Ready process to run. May be modified dynamically by the OS. ix. Blocked information: Flags and messages indicating why the process is blocked. x. Resources: e.g. Open files

7 coe518 (Operating Systems) Lecture Notes: Week 4 Page 7 of 11 Processes should not interfere with one another. In particular, Process A should not be able to read or modify any memory location belonging to Process B. Modern processors usually have hardware and OS software that prevents this from happening no matter how buggy a process may be. Smaller processors (such as the 68hc12) do not have this capability. Multitasking OSes can still be used but all processes must be carefully tested to ensure that they do not access memory not belonging to them. Most processors (except those those for tiny embedded systems) offer the memory management hardware that the OS programs to ensure that processes do not interfere with each others memory. (Most processors go even further than this minimum requirement and allow virtual memory to be used.) There are also certain things that only the OS should be able to do. For example, if concurrent processes were both allowed to access the same physical printer, the printed result would be gibberish a mishmash of the two outputs. This means that the OS code (even at the machine language level) must be able to do things that ordinary user written code cannot do. For example, a user should not be allowed to run an assembly language program that disables interrupts while OS code should be allowed to disable interrupts. This requires that the CPU have at least 2 modes of operation: Kernel: all machine language instructions are allowable. User: Attempts to execute certain instructions (such as disable interrupts) result in an Illegal Instruction Exception. Processor capabilities OK, we need kernel and user modes. Question: But how does the CPU switch from one mode to another? Answer: Any interrupt (hardware or software) puts the CPU into kernel mode. Once the interrupt has been handled (and this may put the current process into the BLOCKED state in which case the scheduler will be invoked), the kernel will eventually return from the interrupt (the equivalent of the rti instruction on the 68hc12 although this CPU does not have separate kernel/user modes) and the previous mode will be restored. If the previous mode were user, that mode is resumed. Similarly, if the interrupt occurred during kernel mode, the rti instruction will maintain the CPU in kernel mode. Question: How does an application programmer get access to an I/O device (keyboard or window) or any other service that only the OS can do? Answer: Suppose the application programmer is writing in assembler (and high level languages

8 coe518 (Operating Systems) Lecture Notes: Week 4 Page 8 of 11 are ultimately translated to machine language). The programmer may want to output Hello world\n and would set up the parameters to the printf subroutine (which they did not write) and then code something like JumpToSubroutine _printf That subroutine will then ask the OS to perform the actual output. But jsr doesn't cut it since that does not change the CPU mode to kernel. Instead, a software interrupt (or trap ) instruction is executed to to request the OS service. The user program indicates the nature of the request and its parameters in specific machine registers. Once in kernel mode the OS code examines the request and, if it is legal performs it and eventually returns from interrupt which puts the CPU into its previous mode (user) and the user code continues. Note that when the CPU is in kernel mode, it is still executing on behalf of the same process. The CPU utilization statistics (maintained in the Process Control Block) keep track of the time spent in each mode. This can be demonstrated by timing the execution of the following two silly programs. /* Compute a lot: mainly user mode */ #include <stdlib.h> main() { int i; for(i = 0; i < ; i++); exit(0); /* Do a lot of output (to /dev/null!!): more kernel mode */ #include <stdlib.h> #include <unistd.h> #include <stdio.h> main() { int i; for(i = 0; i < ; i++) { // putchar('a'); // fflush(stdout); write(1, "abc", 1); //OS call to output 1 char exit(0); Following is the output of the time command using the cygwin bash shell under Windows 7 on an AMD dual-core C-50 processor. $ time./outalot.exe > /dev/null real 0m15.307s

9 coe518 (Operating Systems) Lecture Notes: Week 4 Page 9 of 11 user sys 0m8.735s 0m5.849s $ time./computealot.exe real user sys 0m10.178s 0m9.344s 0m0.139s More about threads Threads are similar to processes: only one threat at a time can execute on a CPU. One process can contain multiple threads. Unlike processes (which have independent unshared resources such as memory and files), threads within a process share all of the processes resources. Because another set of resources do not have to be enabled when switching from one thread to another (in the same process), the context switching is much faster for a thread than for a process. Note: processes are sometimes call Heavyweight Processes and threads Lightweight Processes. Programmers writing single-threaded applications rarely have to be concerned about interprocess communication and resource sharing problems. (The OS takes care of most of these details.) But application programmers writing multithreaded apps do need to be concerned about these things to avoid problems like deadlock and starvation (topics we will examine shortly). For example, virtually all Graphical User Interface programs are multithreaded (one thread to interact with the user and other threads to do the actual computation.) Fortunately, modern GUI frameworks hide these nasty details from the programmer with library classes that take care of the details. However, explicit multithreading is increasingly popular due to the explosive growth in multicore processors. (i.e. A single threaded process cannot take advantage of the other cores.) Amdahl's Law Gene Amdahl showed the following potential speedup factor for a multitasking program where there are N processors and a fraction, f, of the code that is necessarily sequential (cannot be parallelized).

10 coe518 (Operating Systems) Lecture Notes: Week 4 Page 10 of 11 Speedup= 1 f + (1 f ) N Questions 1. An initially empty Delta List is initialized at time 0 so that the following events will be triggered at the indicated times: Event time 20; Event B@ time 40; Event time 30; a. Show what the list looks like following this initialization. b. Show what the list looks like 15 ticks later. c. One tick later (16 ticks from the beginning) two events are added: Event D to be triggered 10 ticks later and Event E to be triggered 50 ticks later. Show the resulting Delta List. 2. A browser can implement tabs using separate processes or separate threads for each tab. Give one advantage and one disadvantage of using processes rather than threads. 3. Consider searching through a collection of items to see if a particular item exists. a. What fraction of the code is necessarily sequential? b. If finding the answer takes 10 seconds with one processor, how long will it take with 100 cores? 4. Suppose we have a CPU with 2 modes of operation: user and kernel. The OS has a subroutine called lauch\nuclearmisslesanddestroytheplanet. Why is it impossible for an ordinary application programmer to kill us all? Answers 1. a. A:20 -> C:10 -> B:10->null b. A:5 -> C:10 -> B:10 -> null

11 coe518 (Operating Systems) Lecture Notes: Week 4 Page 11 of 11 c. A:4 -> D:6 -> C:4 -> B:10 -> E:10 2. Advantage: A bug in one tab cannot crash other tabs. Disadvantage: Slower. 3. There is no essential sequential code. (Each of N processors can search 1/N of the search space.) So 100 processors can perform the task in 0.1 seconds. 4. If a program in user mode attempted jsr lauchnuclearmisslesanddestroytheplanet the OS (and memory management hardware) would recognize that the attempt to access a subroutine in kernal space was illegal. Even if the user knew the special software interrupt instruction and parameters needed to access this kernel subroutine,the kernel OS code could then verify that the user had permission to use this subroutine and deny access if they were not authorized to do so. (Your professor thinks that a well-written OS should deny access to anyone trying to execute such code.)

518 Lecture Notes Week 3

518 Lecture Notes Week 3 518 Lecture Notes Week 3 (Sept. 15, 2014) 1/8 518 Lecture Notes Week 3 1 Topics Process management Process creation with fork() Overlaying an existing process with exec Notes on Lab 3 2 Process management

More information

628 Lecture Notes Week 4

628 Lecture Notes Week 4 628 Lecture Notes Week 4 (February 3, 2016) 1/8 628 Lecture Notes Week 4 1 Topics I/O Redirection Notes on Lab 4 Introduction to Threads Review Memory spaces #include #include int

More information

COE518 Lecture Notes Week 2 (Sept. 12, 2011)

COE518 Lecture Notes Week 2 (Sept. 12, 2011) C)E 518 Operating Systems Week 2 September 12, 2011 1/8 COE518 Lecture Notes Week 2 (Sept. 12, 2011) Topics Creating a cloned process with fork() Running a new process with exec...() Textbook sections

More information

Week 2 Intro to the Shell with Fork, Exec, Wait. Sarah Diesburg Operating Systems CS 3430

Week 2 Intro to the Shell with Fork, Exec, Wait. Sarah Diesburg Operating Systems CS 3430 Week 2 Intro to the Shell with Fork, Exec, Wait Sarah Diesburg Operating Systems CS 3430 1 Why is the Shell Important? Shells provide us with a way to interact with the core system Executes programs on

More information

The Process Abstraction. CMPU 334 Operating Systems Jason Waterman

The Process Abstraction. CMPU 334 Operating Systems Jason Waterman The Process Abstraction CMPU 334 Operating Systems Jason Waterman How to Provide the Illusion of Many CPUs? Goal: run N processes at once even though there are M CPUs N >> M CPU virtualizing The OS can

More information

Process Management 1

Process Management 1 Process Management 1 Goals of this Lecture Help you learn about: Creating new processes Programmatically redirecting stdin, stdout, and stderr (Appendix) communication between processes via pipes Why?

More information

Process Management! Goals of this Lecture!

Process Management! Goals of this Lecture! Process Management! 1 Goals of this Lecture! Help you learn about:" Creating new processes" Programmatically redirecting stdin, stdout, and stderr" (Appendix) communication between processes via pipes"

More information

CS240: Programming in C

CS240: Programming in C CS240: Programming in C Lecture 16: Process and Signals Cristina Nita-Rotaru Lecture 16/ Fall 2013 1 Processes in UNIX UNIX identifies processes via a unique Process ID Each process also knows its parent

More information

Killing Zombies, Working, Sleeping, and Spawning Children

Killing Zombies, Working, Sleeping, and Spawning Children Killing Zombies, Working, Sleeping, and Spawning Children CS 333 Prof. Karavanic (c) 2015 Karen L. Karavanic 1 The Process Model The OS loads program code and starts each job. Then it cleans up afterwards,

More information

* What are the different states for a task in an OS?

* What are the different states for a task in an OS? * Kernel, Services, Libraries, Application: define the 4 terms, and their roles. The kernel is a computer program that manages input/output requests from software, and translates them into data processing

More information

TCSS 422: OPERATING SYSTEMS

TCSS 422: OPERATING SYSTEMS TCSS 422: OPERATING SYSTEMS fork() Process API, Limited Direct Execution Wes J. Lloyd Institute of Technology University of Washington - Tacoma Creates a new process - think of a fork in the road Parent

More information

The Kernel Abstraction. Chapter 2 OSPP Part I

The Kernel Abstraction. Chapter 2 OSPP Part I The Kernel Abstraction Chapter 2 OSPP Part I Kernel The software component that controls the hardware directly, and implements the core privileged OS functions. Modern hardware has features that allow

More information

Fall 2015 COMP Operating Systems. Lab #3

Fall 2015 COMP Operating Systems. Lab #3 Fall 2015 COMP 3511 Operating Systems Lab #3 Outline n Operating System Debugging, Generation and System Boot n Review Questions n Process Control n UNIX fork() and Examples on fork() n exec family: execute

More information

CS 326: Operating Systems. Process Execution. Lecture 5

CS 326: Operating Systems. Process Execution. Lecture 5 CS 326: Operating Systems Process Execution Lecture 5 Today s Schedule Process Creation Threads Limited Direct Execution Basic Scheduling 2/5/18 CS 326: Operating Systems 2 Today s Schedule Process Creation

More information

Process Management! Goals of this Lecture!

Process Management! Goals of this Lecture! Process Management! 1 Goals of this Lecture! Help you learn about:" Creating new processes" Programmatically redirecting stdin, stdout, and stderr" Unix system-level functions for I/O" The Unix stream

More information

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras Week - 01 Lecture - 03 From Programs to Processes Hello. In

More information

PROCESS CONTROL BLOCK TWO-STATE MODEL (CONT D)

PROCESS CONTROL BLOCK TWO-STATE MODEL (CONT D) MANAGEMENT OF APPLICATION EXECUTION PROCESS CONTROL BLOCK Resources (processor, I/O devices, etc.) are made available to multiple applications The processor in particular is switched among multiple applications

More information

Unix-Linux 2. Unix is supposed to leave room in the process table for a superuser process that could be used to kill errant processes.

Unix-Linux 2. Unix is supposed to leave room in the process table for a superuser process that could be used to kill errant processes. Unix-Linux 2 fork( ) system call is successful parent suspended child created fork( ) returns child pid to parent fork( ) returns zero value to child; zero is the pid of the swapper/scheduler process both

More information

518 Lecture Notes Week 5

518 Lecture Notes Week 5 518 Lecture Notes Week 5 (Sept. 29, 2014) 1/6 518 Lecture Notes Week 5 1 Topics Introduction to Threads 2 An introduction to Threads (continued from Week 4) Note: This is a continuation of last week's

More information

Chapter 3: Processes. Operating System Concepts 8th Edition,

Chapter 3: Processes. Operating System Concepts 8th Edition, Chapter 3: Processes, Administrivia Friday: lab day. For Monday: Read Chapter 4. Written assignment due Wednesday, Feb. 25 see web site. 3.2 Outline What is a process? How is a process represented? Process

More information

Operating Systems & Concurrency: Process Concepts

Operating Systems & Concurrency: Process Concepts Operating Systems & Concurrency: Process Concepts Michael Brockway October 6, 2011 Outline Processes - context, data area, states Process creation, termination unix examples Processes and threads Processes

More information

CSC 1600 Unix Processes. Goals of This Lecture

CSC 1600 Unix Processes. Goals of This Lecture CSC 1600 Unix Processes q Processes Goals of This Lecture q Process vs. program q Context switching q Creating a new process q fork: process creates a new child process q wait: parent waits for child process

More information

Preview. Process Control. What is process? Process identifier The fork() System Call File Sharing Race Condition. COSC350 System Software, Fall

Preview. Process Control. What is process? Process identifier The fork() System Call File Sharing Race Condition. COSC350 System Software, Fall Preview Process Control What is process? Process identifier The fork() System Call File Sharing Race Condition COSC350 System Software, Fall 2015 1 Von Neumann Computer Architecture: An integrated set

More information

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo PROCESS MANAGEMENT Operating Systems 2015 Spring by Euiseong Seo Today s Topics Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication

More information

Processes. CS439: Principles of Computer Systems January 24, 2018

Processes. CS439: Principles of Computer Systems January 24, 2018 Processes CS439: Principles of Computer Systems January 24, 2018 Last Time History Lesson Hardware expensive, humans cheap Hardware cheap, humans expensive Hardware very cheap, humans very expensive Dual-mode

More information

Agenda Process Concept Process Scheduling Operations on Processes Interprocess Communication 3.2

Agenda Process Concept Process Scheduling Operations on Processes Interprocess Communication 3.2 Lecture 3: Processes Agenda Process Concept Process Scheduling Operations on Processes Interprocess Communication 3.2 Process in General 3.3 Process Concept Process is an active program in execution; process

More information

csci3411: Operating Systems

csci3411: Operating Systems csci3411: Operating Systems Lecture 3: System structure and Processes Gabriel Parmer Some slide material from Silberschatz and West System Structure System Structure How different parts of software 1)

More information

Process Concepts. CSC400 - Operating Systems. 3. Process Concepts. J. Sumey

Process Concepts. CSC400 - Operating Systems. 3. Process Concepts. J. Sumey CSC400 - Operating Systems 3. Process Concepts J. Sumey Overview Concurrency Processes & Process States Process Accounting Interrupts & Interrupt Processing Interprocess Communication CSC400 - Process

More information

Lecture Topics. Announcements. Today: Threads (Stallings, chapter , 4.6) Next: Concurrency (Stallings, chapter , 5.

Lecture Topics. Announcements. Today: Threads (Stallings, chapter , 4.6) Next: Concurrency (Stallings, chapter , 5. Lecture Topics Today: Threads (Stallings, chapter 4.1-4.3, 4.6) Next: Concurrency (Stallings, chapter 5.1-5.4, 5.7) 1 Announcements Make tutorial Self-Study Exercise #4 Project #2 (due 9/20) Project #3

More information

CSE 451: Operating Systems Winter Module 4 Processes. Mark Zbikowski Allen Center 476

CSE 451: Operating Systems Winter Module 4 Processes. Mark Zbikowski Allen Center 476 CSE 451: Operating Systems Winter 2015 Module 4 Processes Mark Zbikowski mzbik@cs.washington.edu Allen Center 476 2013 Gribble, Lazowska, Levy, Zahorjan Process management This module begins a series of

More information

Processes. CS439: Principles of Computer Systems January 30, 2019

Processes. CS439: Principles of Computer Systems January 30, 2019 Processes CS439: Principles of Computer Systems January 30, 2019 What We Know Operating system complexity increased over time in response to economic and technological changes The three roles did not show

More information

What Is A Process? Process States. Process Concept. Process Control Block (PCB) Process State Transition Diagram 9/6/2013. Process Fundamentals

What Is A Process? Process States. Process Concept. Process Control Block (PCB) Process State Transition Diagram 9/6/2013. Process Fundamentals What Is A Process? A process is a program in execution. Process Fundamentals #include int main(int argc, char*argv[]) { int v; printf( hello world\n ); scanf( %d, &v); return 0; Program test

More information

OS COMPONENTS OVERVIEW OF UNIX FILE I/O. CS124 Operating Systems Fall , Lecture 2

OS COMPONENTS OVERVIEW OF UNIX FILE I/O. CS124 Operating Systems Fall , Lecture 2 OS COMPONENTS OVERVIEW OF UNIX FILE I/O CS124 Operating Systems Fall 2017-2018, Lecture 2 2 Operating System Components (1) Common components of operating systems: Users: Want to solve problems by using

More information

Section 2: Processes

Section 2: Processes September 7, 2016 Contents 1 Warmup 2 1.1 Hello World............................................ 2 2 Vocabulary 2 3 Problems 3 3.1 Forks................................................ 3 3.2 Stack Allocation.........................................

More information

Process management. What s in a process? What is a process? The OS s process namespace. A process s address space (idealized)

Process management. What s in a process? What is a process? The OS s process namespace. A process s address space (idealized) Process management CSE 451: Operating Systems Spring 2012 Module 4 Processes Ed Lazowska lazowska@cs.washington.edu Allen Center 570 This module begins a series of topics on processes, threads, and synchronization

More information

Unix Processes. What is a Process?

Unix Processes. What is a Process? Unix Processes Process -- program in execution shell spawns a process for each command and terminates it when the command completes Many processes all multiplexed to a single processor (or a small number

More information

Introduction to OS Processes in Unix, Linux, and Windows MOS 2.1 Mahmoud El-Gayyar

Introduction to OS Processes in Unix, Linux, and Windows MOS 2.1 Mahmoud El-Gayyar Introduction to OS Processes in Unix, Linux, and Windows MOS 2.1 Mahmoud El-Gayyar elgayyar@ci.suez.edu.eg Mahmoud El-Gayyar / Introduction to OS 1 Processes in Unix, Linux, and Windows Unix pre-empted

More information

CS240: Programming in C

CS240: Programming in C CS240: Programming in C Lecture 17: Processes, Pipes, and Signals Cristina Nita-Rotaru Lecture 17/ Fall 2013 1 Processes in UNIX UNIX identifies processes via a unique Process ID Each process also knows

More information

ENGR 3950U / CSCI 3020U Midterm Exam SOLUTIONS, Fall 2012 SOLUTIONS

ENGR 3950U / CSCI 3020U Midterm Exam SOLUTIONS, Fall 2012 SOLUTIONS SOLUTIONS ENGR 3950U / CSCI 3020U (Operating Systems) Midterm Exam October 23, 2012, Duration: 80 Minutes (10 pages, 12 questions, 100 Marks) Instructor: Dr. Kamran Sartipi Question 1 (Computer Systgem)

More information

System Call. Preview. System Call. System Call. System Call 9/7/2018

System Call. Preview. System Call. System Call. System Call 9/7/2018 Preview Operating System Structure Monolithic Layered System Microkernel Virtual Machine Process Management Process Models Process Creation Process Termination Process State Process Implementation Operating

More information

Processes. CS3026 Operating Systems Lecture 05

Processes. CS3026 Operating Systems Lecture 05 Processes CS3026 Operating Systems Lecture 05 Dispatcher Admit Ready Queue Dispatch Processor Release Timeout or Yield Event Occurs Blocked Queue Event Wait Implementation: Using one Ready and one Blocked

More information

CS 33. Architecture and the OS. CS33 Intro to Computer Systems XIX 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.

CS 33. Architecture and the OS. CS33 Intro to Computer Systems XIX 1 Copyright 2018 Thomas W. Doeppner. All rights reserved. CS 33 Architecture and the OS CS33 Intro to Computer Systems XIX 1 Copyright 2018 Thomas W. Doeppner. All rights reserved. The Operating System My Program Mary s Program Bob s Program OS CS33 Intro to

More information

Creating a Shell or Command Interperter Program CSCI411 Lab

Creating a Shell or Command Interperter Program CSCI411 Lab Creating a Shell or Command Interperter Program CSCI411 Lab Adapted from Linux Kernel Projects by Gary Nutt and Operating Systems by Tannenbaum Exercise Goal: You will learn how to write a LINUX shell

More information

Lecture 4: Process Management

Lecture 4: Process Management Lecture 4: Process Management (Chapters 2-3) Process: execution context of running program. A process does not equal a program! Process is an instance of a program Many copies of same program can be running

More information

Chapter 3: Process Concept

Chapter 3: Process Concept Chapter 3: Process Concept Chapter 3: Process Concept Process Concept Process Scheduling Operations on Processes Inter-Process Communication (IPC) Communication in Client-Server Systems Objectives 3.2

More information

Chapter 3: Process Concept

Chapter 3: Process Concept Chapter 3: Process Concept Chapter 3: Process Concept Process Concept Process Scheduling Operations on Processes Inter-Process Communication (IPC) Communication in Client-Server Systems Objectives 3.2

More information

Mon Sep 17, 2007 Lecture 3: Process Management

Mon Sep 17, 2007 Lecture 3: Process Management Mon Sep 17, 2007 Lecture 3: Process Management September 19, 2007 1 Review OS mediates between hardware and user software QUIZ: Q: Name three layers of a computer system where the OS is one of these layers.

More information

Processes COMPSCI 386

Processes COMPSCI 386 Processes COMPSCI 386 Elements of a Process A process is a program in execution. Distinct processes may be created from the same program, but they are separate execution sequences. call stack heap STACK

More information

Processes. Dr. Yingwu Zhu

Processes. Dr. Yingwu Zhu Processes Dr. Yingwu Zhu Process Growing Memory Stack expands automatically Data area (heap) can grow via a system call that requests more memory - malloc() in c/c++ Entering the kernel (mode) Hardware

More information

coe628 Final Study Guide (2017)

coe628 Final Study Guide (2017) coe628 Final Study Guide 2017 1/6 coe628 Final Study Guide (2017) Table of Contents What is a Study Guide?...1 The Questions...2 Address of global variables in forked processes...2 Memory spaces...3 Amdahl

More information

4.8 Summary. Practice Exercises

4.8 Summary. Practice Exercises Practice Exercises 191 structures of the parent process. A new task is also created when the clone() system call is made. However, rather than copying all data structures, the new task points to the data

More information

Processes. Operating System CS 217. Supports virtual machines. Provides services: User Process. User Process. OS Kernel. Hardware

Processes. Operating System CS 217. Supports virtual machines. Provides services: User Process. User Process. OS Kernel. Hardware es CS 217 Operating System Supports virtual machines Promises each process the illusion of having whole machine to itself Provides services: Protection Scheduling Memory management File systems Synchronization

More information

CS 355 Operating Systems. Keeping Track of Processes. When are processes created? Process States 1/26/18. Processes, Unix Processes and System Calls

CS 355 Operating Systems. Keeping Track of Processes. When are processes created? Process States 1/26/18. Processes, Unix Processes and System Calls CS 355 Operating Systems Processes, Unix Processes and System Calls Process User types command like run foo at keyboard I/O device driver for keyboard and screen Command is parsed by command shell Executable

More information

Operating System Design

Operating System Design Operating System Design Processes Operations Inter Process Communication (IPC) Neda Nasiriani Fall 2018 1 Process 2 Process Lifecycle 3 What information is needed? If you want to design a scheduler to

More information

Chapter 3: Process Concept

Chapter 3: Process Concept Chapter 3: Process Concept Silberschatz, Galvin and Gagne 2013! Chapter 3: Process Concept Process Concept" Process Scheduling" Operations on Processes" Inter-Process Communication (IPC)" Communication

More information

Prepared by Prof. Hui Jiang Process. Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University

Prepared by Prof. Hui Jiang Process. Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University EECS3221.3 Operating System Fundamentals No.2 Process Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University How OS manages CPU usage? How CPU is used? Users use CPU to run

More information

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Processes Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu OS Internals User space shell ls trap shell ps Kernel space File System Management I/O

More information

Process. Prepared by Prof. Hui Jiang Dept. of EECS, York Univ. 1. Process in Memory (I) PROCESS. Process. How OS manages CPU usage? No.

Process. Prepared by Prof. Hui Jiang Dept. of EECS, York Univ. 1. Process in Memory (I) PROCESS. Process. How OS manages CPU usage? No. EECS3221.3 Operating System Fundamentals No.2 Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University How OS manages CPU usage? How CPU is used? Users use CPU to run programs

More information

Processes. Johan Montelius KTH

Processes. Johan Montelius KTH Processes Johan Montelius KTH 2017 1 / 47 A process What is a process?... a computation a program i.e. a sequence of operations a set of data structures a set of registers means to interact with other

More information

Process Control. Philipp Koehn. 23 April 2018

Process Control. Philipp Koehn. 23 April 2018 Process Control Philipp Koehn 23 April 2018 Control Flow 1 The CPU executes one instruction after another Typically, they are next to each other in memory (unless jumps, branches, and returns from subroutine)

More information

Process a program in execution; process execution must progress in sequential fashion. Operating Systems

Process a program in execution; process execution must progress in sequential fashion. Operating Systems Process Concept An operating system executes a variety of programs: Batch system jobs Time-shared systems user programs or tasks 1 Textbook uses the terms job and process almost interchangeably Process

More information

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 20

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 20 CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2018 Lecture 20 LAST TIME: UNIX PROCESS MODEL Began covering the UNIX process model and API Information associated with each process: A PID (process ID) to

More information

Sistemi in Tempo Reale

Sistemi in Tempo Reale Laurea Specialistica in Ingegneria dell'automazione Sistemi in Tempo Reale Giuseppe Lipari Introduzione alla concorrenza Fundamentals Algorithm: It is the logical procedure to solve a certain problem It

More information

A process. the stack

A process. the stack A process Processes Johan Montelius What is a process?... a computation KTH 2017 a program i.e. a sequence of operations a set of data structures a set of registers means to interact with other processes

More information

CSE 410: Computer Systems Spring Processes. John Zahorjan Allen Center 534

CSE 410: Computer Systems Spring Processes. John Zahorjan Allen Center 534 CSE 410: Computer Systems Spring 2018 Processes John Zahorjan zahorjan@cs.washington.edu Allen Center 534 1. What is a process? Processes 2. What's the process namespace? 3. How are processes represented

More information

CS 3113 Introduction to Operating Systems Midterm October 11, 2018

CS 3113 Introduction to Operating Systems Midterm October 11, 2018 General instructions: CS 3113 Introduction to Operating Systems Midterm October 11, 2018 Please wait to open this exam booklet until you are told to do so. This examination booklet has 10 pages. You also

More information

CS 3113 Introduction to Operating Systems Midterm October 11, 2018

CS 3113 Introduction to Operating Systems Midterm October 11, 2018 General instructions: CS 3113 Introduction to Operating Systems Midterm October 11, 2018 Please wait to open this exam booklet until you are told to do so. This examination booklet has 10 pages. You also

More information

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras Week 03 Lecture 12 Create, Execute, and Exit from a Process

More information

Process Turnaround Time Total Wait Time P 1 12 ms 0 ms P 2 21 ms 12 ms P 3 23 ms 18 ms P 4 20 ms 17 ms

Process Turnaround Time Total Wait Time P 1 12 ms 0 ms P 2 21 ms 12 ms P 3 23 ms 18 ms P 4 20 ms 17 ms Name: SOLUTIONS Score: / 100 CSCI-4210/6140 Operating Systems Midterm Exam Thursday 10/9 1-PAGE (2-SIDED) CRIB SHEET ALLOWED; NO CALCULATOR ANSWER ALL QUESTIONS; USE EXTRA PAPER AS NECESSARY 1. [25 POINTS]

More information

Solutions to the first midterm. COSC 4330/6310 Summer 2013

Solutions to the first midterm. COSC 4330/6310 Summer 2013 Solutions to the first midterm COSC 4330/6310 Summer 2013 First question a) Give an example of a popular operating system using a UNIX or a Linux kernel. b) Give an example of a real-time process with

More information

CS 33. Architecture and the OS. CS33 Intro to Computer Systems XIX 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

CS 33. Architecture and the OS. CS33 Intro to Computer Systems XIX 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. CS 33 Architecture and the OS CS33 Intro to Computer Systems XIX 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. The Operating System My Program Mary s Program Bob s Program OS CS33 Intro to

More information

Roadmap. Tevfik Ko!ar. CSC Operating Systems Spring Lecture - III Processes. Louisiana State University. Virtual Machines Processes

Roadmap. Tevfik Ko!ar. CSC Operating Systems Spring Lecture - III Processes. Louisiana State University. Virtual Machines Processes CSC 4103 - Operating Systems Spring 2008 Lecture - III Processes Tevfik Ko!ar Louisiana State University January 22 nd, 2008 1 Roadmap Virtual Machines Processes Basic Concepts Context Switching Process

More information

Notice: This set of slides is based on the notes by Professor Perrone of Bucknell and the textbook authors Silberschatz, Galvin, and Gagne

Notice: This set of slides is based on the notes by Professor Perrone of Bucknell and the textbook authors Silberschatz, Galvin, and Gagne Process Fundamentals Notice: This set of slides is based on the notes by Professor Perrone of Bucknell and the textbook authors Silberschatz, Galvin, and Gagne CSCI 315 Operating Systems Design 1 What

More information

Operating Systemss and Multicore Programming (1DT089)

Operating Systemss and Multicore Programming (1DT089) Operating Systemss and Multicore Programming (1DT089) The Process Concept and Inter Processs Communication (Chapter 3) Tuesday january 28 Uppsala University 2014 karl.marklund@it.uu.se 1.5.1) Dual-Mode

More information

Announcement. Exercise #2 will be out today. Due date is next Monday

Announcement. Exercise #2 will be out today. Due date is next Monday Announcement Exercise #2 will be out today Due date is next Monday Major OS Developments 2 Evolution of Operating Systems Generations include: Serial Processing Simple Batch Systems Multiprogrammed Batch

More information

Process Description and Control

Process Description and Control Process Description and Control B.Ramamurthy 1/28/02 B.Ramamurthy 1 Introduction The fundamental task of any operating system is process management. OS must allocate resources to processes, enable sharing

More information

Operating systems Portfolio

Operating systems Portfolio Operating systems Portfolio Thebault Yann Student number : 10004434 CE0100-3 Operating systems! Friday 26 November 2010 WEEK 1 6. How does the distinction between supervisor mode and user mode function

More information

UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4500/8506 Operating Systems Fall Programming Assignment 1 (updated 9/16/2017)

UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4500/8506 Operating Systems Fall Programming Assignment 1 (updated 9/16/2017) UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4500/8506 Operating Systems Fall 2017 Programming Assignment 1 (updated 9/16/2017) Introduction The purpose of this programming assignment is to give you

More information

What is a Process. Processes. Programs and Processes. System Classification 3/5/2013. Process: An execution stream and its associated state

What is a Process. Processes. Programs and Processes. System Classification 3/5/2013. Process: An execution stream and its associated state What is a Process Process: An execution stream and its associated state Processes Execution Stream Set of instructions Thread of control Process State Hardware state Privilege level, segments, page tables

More information

Maria Hybinette, UGA. ! One easy way to communicate is to use files. ! File descriptors. 3 Maria Hybinette, UGA. ! Simple example: who sort

Maria Hybinette, UGA. ! One easy way to communicate is to use files. ! File descriptors. 3 Maria Hybinette, UGA. ! Simple example: who sort Two Communicating Processes Hello Gunnar CSCI 6730/ 4730 Operating Systems Process Chat Maria A Hi Nice to Hear from you Process Chat Gunnar B Dup & Concept that we want to implement 2 On the path to communication

More information

Chapter 3: Process-Concept. Operating System Concepts 8 th Edition,

Chapter 3: Process-Concept. Operating System Concepts 8 th Edition, Chapter 3: Process-Concept, Silberschatz, Galvin and Gagne 2009 Chapter 3: Process-Concept Process Concept Process Scheduling Operations on Processes Interprocess Communication 3.2 Silberschatz, Galvin

More information

OS lpr. www. nfsd gcc emacs ls 1/27/09. Process Management. CS 537 Lecture 3: Processes. Example OS in operation. Why Processes? Simplicity + Speed

OS lpr. www. nfsd gcc emacs ls 1/27/09. Process Management. CS 537 Lecture 3: Processes. Example OS in operation. Why Processes? Simplicity + Speed Process Management CS 537 Lecture 3: Processes Michael Swift This lecture begins a series of topics on processes, threads, and synchronization Today: processes and process management what are the OS units

More information

What is a Process. Preview. What is a Process. What is a Process. Process Instruction Cycle. Process Instruction Cycle 3/14/2018.

What is a Process. Preview. What is a Process. What is a Process. Process Instruction Cycle. Process Instruction Cycle 3/14/2018. Preview Process Control What is process? Process identifier A key concept in OS is the process Process a program in execution Once a process is created, OS not only reserve space (in Memory) for the process

More information

Processes, Threads, SMP, and Microkernels

Processes, Threads, SMP, and Microkernels Processes, Threads, SMP, and Microkernels Slides are mainly taken from «Operating Systems: Internals and Design Principles, 6/E William Stallings (Chapter 4). Some materials and figures are obtained from

More information

Lecture 7: file I/O, more Unix

Lecture 7: file I/O, more Unix CIS 330: / / / / (_) / / / / _/_/ / / / / / \/ / /_/ / `/ \/ / / / _/_// / / / / /_ / /_/ / / / / /> < / /_/ / / / / /_/ / / / /_/ / / / / / \ /_/ /_/_/_/ _ \,_/_/ /_/\,_/ \ /_/ \ //_/ /_/ Lecture 7: file

More information

Operating systems and concurrency - B03

Operating systems and concurrency - B03 Operating systems and concurrency - B03 David Kendall Northumbria University David Kendall (Northumbria University) Operating systems and concurrency - B03 1 / 15 Introduction This lecture gives a more

More information

COP 4610: Introduction to Operating Systems (Spring 2016) Chapter 3: Process. Zhi Wang Florida State University

COP 4610: Introduction to Operating Systems (Spring 2016) Chapter 3: Process. Zhi Wang Florida State University COP 4610: Introduction to Operating Systems (Spring 2016) Chapter 3: Process Zhi Wang Florida State University Contents Process concept Process scheduling Operations on processes Inter-process communication

More information

CPS 310 first midterm exam, 10/6/2014

CPS 310 first midterm exam, 10/6/2014 CPS 310 first midterm exam, 10/6/2014 Your name please: Part 1. More fun with fork and exec* What is the output generated by this program? Please assume that each executed print statement completes, e.g.,

More information

CS5460: Operating Systems

CS5460: Operating Systems CS5460: Operating Systems Lecture 5: Processes and Threads (Chapters 3-4) Context Switch Results lab2-15 gamow home 3.8 us 1.6 us 1.0 us VirtualBox on lab2-25 VirtualBox on gamow VirtualBox on home 170

More information

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto Ricardo Rocha Department of Computer Science Faculty of Sciences University of Porto Slides based on the book Operating System Concepts, 9th Edition, Abraham Silberschatz, Peter B. Galvin and Greg Gagne,

More information

CPSC 341 OS & Networks. Processes. Dr. Yingwu Zhu

CPSC 341 OS & Networks. Processes. Dr. Yingwu Zhu CPSC 341 OS & Networks Processes Dr. Yingwu Zhu Process Concept Process a program in execution What is not a process? -- program on a disk A process is an active object, but a program is just a file It

More information

Definition: An operating system is the software that manages resources

Definition: An operating system is the software that manages resources 13-1 Operating Systems 13-1 Definition: An operating system is the software that manages resources in a computer. Resources A resource is (usually) hardware that needs to be accessed. There are rules for

More information

IPC and Unix Special Files

IPC and Unix Special Files Outline IPC and Unix Special Files (USP Chapters 6 and 7) Instructor: Dr. Tongping Liu Inter-Process communication (IPC) Pipe and Its Operations FIFOs: Named Pipes Ø Allow Un-related Processes to Communicate

More information

Process Creation in UNIX

Process Creation in UNIX Process Creation in UNIX int fork() create a child process identical to parent Child process has a copy of the address space of the parent process On success: Both parent and child continue execution at

More information

Coe628 Midterm Study Guide (2017)

Coe628 Midterm Study Guide (2017) Coe628 Study Guide 2017 1/6 Coe628 Midterm Study Guide (2017) The Questions 1. Multi-core state diagram A single CPU (core) has a state transition diagram indicating the possible process state changes

More information

Processes. Overview. Processes. Process Creation. Process Creation fork() Processes. CPU scheduling. Pål Halvorsen 21/9-2005

Processes. Overview. Processes. Process Creation. Process Creation fork() Processes. CPU scheduling. Pål Halvorsen 21/9-2005 INF060: Introduction to Operating Systems and Data Communication Operating Systems: Processes & CPU Pål Halvorsen /9-005 Overview Processes primitives for creation and termination states context switches

More information

PROCESSES. Jo, Heeseung

PROCESSES. Jo, Heeseung PROCESSES Jo, Heeseung TODAY'S TOPICS What is the process? How to implement processes? Inter-Process Communication (IPC) 2 WHAT IS THE PROCESS? Program? vs. Process? vs. Processor? 3 PROCESS CONCEPT (1)

More information

Processes. Jo, Heeseung

Processes. Jo, Heeseung Processes Jo, Heeseung Today's Topics What is the process? How to implement processes? Inter-Process Communication (IPC) 2 What Is The Process? Program? vs. Process? vs. Processor? 3 Process Concept (1)

More information

Roadmap. Tevfik Ko!ar. CSC Operating Systems Fall Lecture - III Processes. Louisiana State University. Processes. September 1 st, 2009

Roadmap. Tevfik Ko!ar. CSC Operating Systems Fall Lecture - III Processes. Louisiana State University. Processes. September 1 st, 2009 CSC 4103 - Operating Systems Fall 2009 Lecture - III Processes Tevfik Ko!ar Louisiana State University September 1 st, 2009 1 Roadmap Processes Basic Concepts Process Creation Process Termination Context

More information

System Calls and Signals: Communication with the OS. System Call. strace./hello. Kernel. Context Switch

System Calls and Signals: Communication with the OS. System Call. strace./hello. Kernel. Context Switch System Calls and Signals: Communication with the OS Jonathan Misurda jmisurda@cs.pitt.edu System Call An operation (function) that an OS provides for running applications to use CS 1550 2077 strace./hello

More information