1 A Seven-State Process Model. 2 CPU Switch From Process to Process Silberschatz, Galvin, and Gagne  1999.

Slides:



Advertisements
Similar presentations
3.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Process An operating system executes a variety of programs: Batch system.
Advertisements

Chapter 3 Process Description and Control
Day 11 Processes. Operating Systems Control Tables.
CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
UNIX Process Control Bach 7 Operating Systems Course Hebrew University Spring 2007.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Objectives Understand Process concept Process scheduling Creating.
Processes CSCI 444/544 Operating Systems Fall 2008.
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
Process in Unix, Linux and Windows CS-3013 C-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
CSSE Operating Systems
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Process Description and Control A process is sometimes called a task, it is a program in execution.
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
Process. Process Concept Process – a program in execution Textbook uses the terms job and process almost interchangeably A process includes: – program.
BINA RAMAMURTHY UNIVERSITY AT BUFFALO System Structure and Process Model 5/30/2013 Amrita-UB-MSES
Process Description and Control
Process Description and Control Chapter 3. Major Requirements of an OS Interleave the execution of several processes to maximize processor utilization.
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Chapter 41 Processes Chapter 4. 2 Processes  Multiprogramming operating systems are built around the concept of process (also called task).  A process.
Multiprogramming CSE451 Andrew Whitaker. Overview Multiprogramming: Running multiple programs “at the same time”  Requires multiplexing (sharing) the.
Processes and Threads CS550 Operating Systems. Processes and Threads These exist only at execution time They have fast state changes -> in memory and.
Operating Systems Chapter 2
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-1 Process Concepts Department of Computer Science and Software.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Processes: program + execution state
Creating and Executing Processes
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-1: Process Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
CE Operating Systems Lecture 10 Processes and process management in Linux.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Cooperating.
Computer Studies (AL) Operating System Process Management - Process.
Processes – Part I Processes – Part I. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Review on OSs Upon brief introduction of OSs,
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Linux Processes Travis Willey Jeff Mihalik. What is a process? A process is a program in execution A process includes: –program counter –stack –data section.
Process Description and Control Chapter 3. Source Modified slides from Missouri U. of Science and Tech.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Chapter 3: Processes Process Concept.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations.
CS241 Systems Programming Discussion Section Week 2 Original slides by: Stephen Kloder.
1 Unix system calls fork( ) wait( ) exit( ). 2 How To Create New Processes? n Underlying mechanism -A process runs fork to create a child process -Parent.
A process is a program in execution A running system consists of multiple processes – OS processes Processes started by the OS to do “system things” –
Topic 3 (Textbook - Chapter 3) Processes
Protection of System Resources
Chapter 3: Processes.
Processes in Unix, Linux, and Windows
System Structure and Process Model
Chapter 3: Processes.
System Structure and Process Model
Structure of Processes
Processes in Unix, Linux, and Windows
CGS 3763 Operating Systems Concepts Spring 2013
System Structure B. Ramamurthy.
Processes in Unix, Linux, and Windows
System Structure and Process Model
Operating Systems Lecture 6.
Chapter 3: Processes.
Process Control B.Ramamurthy 2/22/2019 B.Ramamurthy.
Lecture 6: Multiprogramming and Context Switching
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
Processes in Unix, Linux, and Windows
Processes in Unix and Windows
Process Description and Control in Unix
EECE.4810/EECE.5730 Operating Systems
Process Description and Control in Unix
Chapter 3: Process Concept
EECE.4810/EECE.5730 Operating Systems
Presentation transcript:

1 A Seven-State Process Model

2 CPU Switch From Process to Process Silberschatz, Galvin, and Gagne  1999

3 Steps for Full Process Switch  Save context of CPU including program counter and other registers  Update the PCB of the running process with its new state and other info  Move PCB to appropriate queue Ready, Blocked, etc.  Select another process for execution  Update PCB of the selected process Running  Restore CPU context from PCB of the selected process

4 Execution of the Operating System  We have been thinking of a process as a “user process”  But OS itself is a collection of programs So is the OS a process (or processes) as well?  If so, how is it controlled?  The answer depends on the OS design.  There are variations:

5 Non-process Kernel (traditional)  The concept of process applies only to user programs  OS code is a separate single entity all parts of which execute in privileged mode  OS code never gets executed within a process and is not considered to be a process either (no PCB for the OS, simple mode switch in and out)

6 Execution within User Processes (smaller machines)  Most OS code gets executed within the context of the user process  On Interrupts and Traps: CPU does a mode switch to kernel mode to execute OS routine within the user process  Control passes through process switching functions (outside processes) only when needed to switch to another process   OS viewed as collection of routines called by user to perform various functions

7 Process-based Operating System  The OS is a collection of system processes, outside of user’s address space  Each major kernel service is a separate process  Process switching functions (scheduler, etc.) are executed outside of any process  (Very modular approach…)

8 UNIX Process Management  Most of OS executes within user processes  Uses two categories of processes: System “processes”  run in kernel mode for housekeeping functions (memory allocation, process swapping...) User processes  run in user mode for user programs  run in kernel mode for system calls, traps, and interrupts inside the user’s process image

9 Unix Process State Transition Diagram Sleep = Blocked Preempted: returning to user mode, but kernel schedules another process

Chapter 410 Process Creation (Unix)

11 UNIX Process Creation  Every process, except process 0, is created by the fork() system call fork() allocates entry in process table and assigns a unique PID to the child process child gets a copy of process image of parent: both child and parent share the same code following fork(), different data but fork() returns the PID of the child to the parent process and returns 0 to the child process Optional Exec() system call can be used after a fork to replace the process’ memory space with a new program

12 UNIX Process Creation (2)  Parent process can wait() for completion of child The child process can pass data back to parent via exit() call, picked up by parent via the wait(). Terminated child is a “zombie” if parent does not wait() for it

13 UNIX System Processes  “Boot” loads the kernel image  Process 0 is created at boot time and becomes the “swapper” after forking process 1 (the INIT process)  When a user logs in: process 1 creates a process for that user

14 Unix Tree of Processes Silberschatz, Galvin, and Gagne  1999

15 Unix Subprocesses in more detail Some system calls and how they work:  #include  pid_t fork() Creates new process image which is an (almost) exact copy of the one that invokes it  int execv(char*filename,char* argv[])  int execl(char*filename,char* arg0, char* arg1,… NULL) Replace current process image with one running the named program

16 Wait functions  #include  pid_t waitpid(pid_t pid, int* status_ptr, int options) Waits for completion of a particular child process  pid_t wait(int* status_ptr) Waits for any one child to terminate  pid_t getpid(void) Returns process ID  pid_t getppid(void) (parent ID)

17 /* program to fork a child process */ /* and pass arguments to it */ #include #define BUFFSIZE 8192 int main(void) { int n, status; pid_t pid; char buf[BUFFSIZE], commandname[20]; n=write(STDOUT_FILENO,"\ninput command: ",17); n=read(STDIN_FILENO, buf, BUFFSIZE); buf[n-1] = 0; sscanf(buf,"%s",commandname); if (( pid = fork()) < 0) perror("fork error"); else if (pid==0) if (execlp(commandname,buf,(char *) 0) < 0){ perror("execlp error");exit(1); } if ((pid = waitpid(pid, &status, 0)) < 0) perror("wait error"); n=write(STDOUT_FILENO,"\nDone!\n",7); exit(0); }

18... n=write(STDOUT_FILENO,"\ninput command: ",17); n=read(STDIN_FILENO, buf, BUFFSIZE); buf[n-1] = 0; sscanf(buf,"%s",commandname); if (( pid = fork()) < 0) perror("fork error"); else if (pid==0) if (execlp(commandname,buf,(char *) 0) < 0) { perror("execlp error"); exit(1); /* Exit child process! */ } if ((pid = waitpid(pid, &status, 0)) < 0) perror("wait error"); n=write(STDOUT_FILENO,"\nDone!\n",7); exit(0); } The process executes fork()...

n=write(STDOUT_FILENO,"\ninput command: ",17); n=read(STDIN_FILENO, buf, BUFFSIZE); buf[n-1] = 0; sscanf(buf,"%s",commandname); if (( pid = fork()) < 0) perror("fork error"); else if (pid==0) if (execlp(commandname,buf,(char *)0) < 0){ perror("execlp error"); exit(1); } if ((pid = waitpid(pid, &status, 0)) < 0) perror("wait error"); n=write(STDOUT_FILENO,"\nDone!\n",7); exit(0); } n=write(STDOUT_FILENO,"\ninput command: ",17); n=read(STDIN_FILENO, buf, BUFFSIZE); buf[n-1] = 0; sscanf(buf,"%s",commandname); if (( pid = fork()) < 0) perror("fork error"); else if (pid==0) if (execlp(commandname,buf,(char *) 0) < 0){ perror("execlp error");exit(1); } if ((pid = waitpid(pid, &status, 0)) < 0) perror("wait error"); n=write(STDOUT_FILENO,"\nDone!\n",7); exit(0); } And now there are two! (identical process images running the same program)

n=write(STDOUT_FILENO,"\ninput command: ",17); n=read(STDIN_FILENO, buf, BUFFSIZE); buf[n-1] = 0; sscanf(buf,"%s",commandname); if (( pid = fork()) < 0) perror("fork error"); else if (pid==0) if (execlp(commandname,buf,(char *)0) < 0){ perror("execlp error");exit(1); } if ((pid = waitpid(pid, &status, 0)) < 0) perror("wait error"); n=write(STDOUT_FILENO,"\nDone!\n",7); exit(0); } n=write(STDOUT_FILENO,"\ninput command: ",17); n=read(STDIN_FILENO, buf, BUFFSIZE); buf[n-1] = 0; sscanf(buf,"%s",commandname); if (( pid = fork()) < 0) perror("fork error"); else if (pid==0) if (execlp(commandname,buf,(char *) 0) < 0) { perror("execlp error"); exit(1); } if ((pid = waitpid(pid, &status, 0)) < 0) perror("wait error"); n=write(STDOUT_FILENO,"\nDone!\n",7); exit(0); } One is the parent.. And one is the child.. The child exec’s..

/* mychild.c */ /* child program prints out argument vector */ #include int main(int argc, char *argv[]) { int i; printf ("number of arguments is %d: \n",argc); for (i=0; i<argc; i++) printf ("argv[%d]: %s\n", i, argv[i]); exit(0); } n=write(STDOUT_FILENO,"\ninput command: ",17); n=read(STDIN_FILENO, buf, BUFFSIZE); buf[n-1] = 0; sscanf(buf,"%s",commandname); if (( pid = fork()) < 0) perror("fork error"); else if (pid==0) if (execlp(commandname,buf,(char *)0) < 0){ perror("execlp error"); exit(1); } if ((pid = waitpid(pid, &status, 0)) < 0) perror("wait error"); n=write(STDOUT_FILENO,"\nDone!\n",7); exit(0); } Now the parent is waiting.. And the child substitutes a whole new process image running a different program (but same process id)..

/* mychild.c */ /* child program prints out argument vector */ #include int main(int argc, char *argv[]) { int i; printf ("number of arguments is %d: \n",argc); for (i=0; i<argc; i++) printf ("argv[%d]: %s\n", i, argv[i]); exit(0); } n=write(STDOUT_FILENO,"\ninput command: ",17); n=read(STDIN_FILENO, buf, BUFFSIZE); buf[n-1] = 0; sscanf(buf,"%s",commandname); if (( pid = fork()) < 0) perror("fork error"); else if (pid==0) if (execlp(commandname,buf,(char *)0) < 0) { perror("execlp error"); exit(1); } if ((pid = waitpid(pid, &status, 0)) < 0) perror("wait error"); n=write(STDOUT_FILENO,"\nDone!\n",7); exit(0); }...the child eventually exits (with an exit status).. The parent waits until...

n=write(STDOUT_FILENO,"\ninput command: ",17); n=read(STDIN_FILENO, buf, BUFFSIZE); buf[n-1] = 0; sscanf(buf,"%s",commandname); if (( pid = fork()) < 0) perror("fork error"); else if (pid==0) if (execlp(commandname,buf,(char *)0) < 0){ perror("execlp error"); exit(1); } if ((pid = waitpid(pid, &status, 0)) < 0) perror("wait error"); n=write(STDOUT_FILENO,"\nDone!\n",7); exit(0); } And then there is only one again...