computer studies (al) operating system process management - process
TRANSCRIPT
![Page 1: Computer Studies (AL) Operating System Process Management - Process](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1d5503460f94c34171/html5/thumbnails/1.jpg)
Computer Studies (AL)
Operating SystemProcess Management - Process
![Page 2: Computer Studies (AL) Operating System Process Management - Process](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1d5503460f94c34171/html5/thumbnails/2.jpg)
Reference Silberschatz, Galvin, Gagne, “Operating
System Concepts 6th Edition”, 2003, Wiley
William Stallings, “Operating Systems Internals and Design Principles”, 2001, Prentice Hall
![Page 3: Computer Studies (AL) Operating System Process Management - Process](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1d5503460f94c34171/html5/thumbnails/3.jpg)
Content Process Concept Process Scheduling Operations on Process Cooperating Processes
![Page 4: Computer Studies (AL) Operating System Process Management - Process](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1d5503460f94c34171/html5/thumbnails/4.jpg)
Process Concept A process is a program in execution A process is more than the program code
Code: text section Value of program counter Process stack (temporary data) Data section (global variables)
![Page 5: Computer Studies (AL) Operating System Process Management - Process](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1d5503460f94c34171/html5/thumbnails/5.jpg)
Process state As a process executes, it changes state
New: The process is begin created Running: Instructions are being executed Waiting: The process is waiting for some event to
occur (such as an I/O completion or reception of a signal)
Ready: The process is waiting to be assigned to a processor
Terminated: The process has finished execution
![Page 6: Computer Studies (AL) Operating System Process Management - Process](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1d5503460f94c34171/html5/thumbnails/6.jpg)
new
waiting
ready running
terminated
admitted
interrupt
Scheduler dispatch
I/O or event completion I/O or event wait
Exit
![Page 7: Computer Studies (AL) Operating System Process Management - Process](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1d5503460f94c34171/html5/thumbnails/7.jpg)
Process Control Block Each process is represented in the operating
control block (PCB), also called task control block Process state Program counter CPU registers CPU-scheduling information Memory-management information Accounting information I/O status inormation
![Page 8: Computer Studies (AL) Operating System Process Management - Process](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1d5503460f94c34171/html5/thumbnails/8.jpg)
Process scheduling The objective of multiprogramming is to have
some process running at all times, so as to maximize CPU utilization
There are several scheduling queues in the system Ready queue: processes that are residing in main
memory and are ready and waiting to execute Device queue: List of processes waiting to I/O device
![Page 9: Computer Studies (AL) Operating System Process Management - Process](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1d5503460f94c34171/html5/thumbnails/9.jpg)
![Page 10: Computer Studies (AL) Operating System Process Management - Process](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1d5503460f94c34171/html5/thumbnails/10.jpg)
Queueing diagram A new process is initially put in the ready queue. It
waits in the ready queue until it is selected for execution (or dispatched)
Once the process is assigned to the CPU and is executing, one of several events could occur: The process could issue and I/O request, and then be
placed in an I/O queue The process could create a new subprocess and wait
for its termination The process could be removed forcibly from the CPU
and be put back in the ready queue.
![Page 11: Computer Studies (AL) Operating System Process Management - Process](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1d5503460f94c34171/html5/thumbnails/11.jpg)
![Page 12: Computer Studies (AL) Operating System Process Management - Process](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1d5503460f94c34171/html5/thumbnails/12.jpg)
Schedulers The Operating System must select, for
scheduling purposes, processes from the queues in some fashion
The selection process is carried out by the appropriate scheduler
![Page 13: Computer Studies (AL) Operating System Process Management - Process](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1d5503460f94c34171/html5/thumbnails/13.jpg)
In batch system (different schedulers) The processes are usually spooled to a
mass-storage device for later execution There are two scheduler:
Long-term scheduler (job scheduler) Selects processes from this pool and loads them
into memory for execution Short-term scheduler (CPU scheduler)
Selects from among processes that are read to execute, and allocates the CPU to one of them.
![Page 14: Computer Studies (AL) Operating System Process Management - Process](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1d5503460f94c34171/html5/thumbnails/14.jpg)
Cont’ The long-term scheduler may control the degree
of multiprogramming. (no. of process in memory) There are two kinds of process:
I/O bound: spend more time on doing I/O than computations
CPU bound: spend more time on doing computations.
The long-term scheduler should select a good process mix between these processes. (better performance)
![Page 15: Computer Studies (AL) Operating System Process Management - Process](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1d5503460f94c34171/html5/thumbnails/15.jpg)
In time-sharing system The long-term scheduler may be absent or
minimal. Unix: no long-term scheduler (only short-
term)
![Page 16: Computer Studies (AL) Operating System Process Management - Process](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1d5503460f94c34171/html5/thumbnails/16.jpg)
Context Switch Switching the CPU to another process requires
saving the state of the old process and loading the saved state for the new process.
This task is known as a context switch. The context is represented in PCB.
Value of CPU registers Process state Memory-management information
![Page 17: Computer Studies (AL) Operating System Process Management - Process](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1d5503460f94c34171/html5/thumbnails/17.jpg)
When context switch occurs The kernel saves the context of the old
process in its PCB and loads the saved context of the new process scheduled to run.
Context switch time is pure overhead, because the system does no useful work while switching.
![Page 18: Computer Studies (AL) Operating System Process Management - Process](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1d5503460f94c34171/html5/thumbnails/18.jpg)
The procedure of context switching form Process A to B involves : Blocking of Process A due to request of I/O resource, time quantum
exceeded etc. (caused an interrupt); O/S taken over control of the CPU; Saving registers into PCB for Process A, and move process PCB to
corresponding queue (ready or blocked queue); Update PCB of the selected process, and memory management data
structure; Load context (registers and PCB etc.) for Process B; Process B resumes execution.
![Page 19: Computer Studies (AL) Operating System Process Management - Process](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1d5503460f94c34171/html5/thumbnails/19.jpg)
Process Creation A process may create several new
processes The creating process: parent The new processes: children
![Page 20: Computer Studies (AL) Operating System Process Management - Process](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1d5503460f94c34171/html5/thumbnails/20.jpg)
When a process creates a new process: The parent continues to execute
concurrently with its children,OR
The parent waits until some or all of its children have terminated.
![Page 21: Computer Studies (AL) Operating System Process Management - Process](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1d5503460f94c34171/html5/thumbnails/21.jpg)
Two possibilities in terms of address space of the new process The child process is a duplicate of the
parent process The child process has a program loaded
into it.
![Page 22: Computer Studies (AL) Operating System Process Management - Process](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1d5503460f94c34171/html5/thumbnails/22.jpg)
E.g. In Unix… Each process is identified by its process
identifier System call:
fork (create new process) execlp (used after fork, replace the process
memory space with a new program) wait (move itseld off the ready queue) Exit (terminate the process)
![Page 23: Computer Studies (AL) Operating System Process Management - Process](https://reader036.vdocuments.site/reader036/viewer/2022062721/56649f1d5503460f94c34171/html5/thumbnails/23.jpg)
C program - fork#include <stdio.h>Main(int argc, char *argv[]){Int pid;
/* fork another process */pid = fork();if (pid <0) {/*error occurred */fprintf(strderr, “Fork Failed”);exit(-1);
}Else if (pid == 0) {/* child process */
execlp(“/bin/ls”, “ls”, NULL);}Else { /* parent process */ /* parent will wait for the child to complete */
Wait(NULL);Printf(“Child Complete”);Exit(0);}
}