Vous êtes sur la page 1sur 19

Chapter 4: Processes

Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication in Client-Server Systems

Operating System Concepts

4.1

Silberschatz, Galvin and Gagne 2002

Process Concept
Process a program in execution.

Process is not just program code,it includes:


program counter Content of processor registers Process stack (function parameters,local

variables,return address) data section(global variables) Program is passive entity, whereas a process is an active entity. If multiple users invoke same copy of the internet explorer,these will be separate processes, despite belonging to the same passive entity.
Operating System Concepts
4.2

Silberschatz, Galvin and Gagne 2002

Process State
As a process executes, it changes state
New: The process is being created. Running: Instructions are being executed.

At one moment of time, only one process can be in running state. Waiting: The process is waiting for some event to occur. Ready: The process is waiting to be assigned to a process. Terminated: The process has finished execution. Many processes can be in the ready and waiting state.
Operating System Concepts
4.3

Silberschatz, Galvin and Gagne 2002

Diagram of Process State

Operating System Concepts

4.4

Silberschatz, Galvin and Gagne 2002

Process Control Block (PCB)


Process is represented in the operating system by

Process Control Block(PCB). PCB contains: Process state (running,ready,waiting) Program Counter CPU registers (accumulator, general-purpose registers) CPU scheduling information (priority and other info) Memory-management information (base and limit registers, page table or segment table) Accounting information (CPU time used, time limits, process numbers etc.) I/O status information (list of I/O devices allocated to the process, list of open files,etc..)
Operating System Concepts
4.5

Silberschatz, Galvin and Gagne 2002

Process Control Block (PCB)

Operating System Concepts

4.6

Silberschatz, Galvin and Gagne 2002

CPU Switch From Process to Process

Operating System Concepts

4.7

Silberschatz, Galvin and Gagne 2002

Process Scheduling
The objective of multiprogramming is to have

some process running all the time, i.e to maximize CPU utilization. The objective of time-sharing system is to switch among processes so frequently that each user is given the impression that he is the sole user of the system. In uniprocessor system, only one process can be in the running state, so other processes must wait until they are scheduled.

Operating System Concepts

4.8

Silberschatz, Galvin and Gagne 2002

Process Scheduling Queues


Job queue set of all processes in the system.

The moment a process enters the system,it is placed in the job queue. Ready queue set of all processes residing in main memory, ready and waiting to execute. This queue is generally maintained as a link-list. Device queues set of processes waiting for an I/O device. Each device has its own separate device queue.

Operating System Concepts

4.9

Silberschatz, Galvin and Gagne 2002

Ready Queue And Various I/O Device Queues

Operating System Concepts

4.10

Silberschatz, Galvin and Gagne 2002

Representation of Process Scheduling

Operating System Concepts

4.11

Silberschatz, Galvin and Gagne 2002

Schedulers
Scheduler Though there are multiple processes

ready to be run, the selection process is required to select the process. This selection process is done by the scheduler. Long-term scheduler (or job scheduler) selects which processes should be brought into the ready queue from the hard disk to the main memory. Short-term scheduler (or CPU scheduler) selects which process should be executed next and allocates CPU to that process. It selects the process from main memory.

Operating System Concepts

4.12

Silberschatz, Galvin and Gagne 2002

Short Term Scheduler


Short term scheduler is executed more

frequently, coz the scheduler has to switch between processes many times. Though the short term scheduler is executed more frequently, it should be very fast, so that minimal time is wasted for switching.

Operating System Concepts

4.13

Silberschatz, Galvin and Gagne 2002

Long Term Scheduler


Long term scheduler is executed less often, so one can

afford to take more time to select the processes from hard disk. Long term scheduler is required only when any one the processes terminates and leaves the system. Long-term scheduler controls the degree of multiprogramming(the number of process in main memory). If the degree of multi-programming is stable then average rate of process creation should be equal to average rate of process departure. I/O bound process If a process takes more time doing I/O than CPU execution, it is called I/O bound process. CPU bound process - If a process takes more time in CPU execution than I/O, it is called CPU bound process. Long term scheduler must select a good mix of CPU and I/O bound processes.
4.14

Operating System Concepts

Silberschatz, Galvin and Gagne 2002

Medium Term Scheduler


In time-sharing system, if long term scheduler has not

selected a good mix of CPU and I/O bound processes, more time is wasted in switching than doing actual work. Medium Term Scheduler removes processes from memory and thus reduces the degree of multiprogramming. The process can be reintroduced into memory and execution can be continued from where it was left. This scheme is called swapping. The process is swapped out, and is later swapped in, by the medium term scheduler. Swapping is necessary to improve the process mix in main memory.

Operating System Concepts

4.15

Silberschatz, Galvin and Gagne 2002

Addition of Medium Term Scheduling

Operating System Concepts

4.16

Silberschatz, Galvin and Gagne 2002

Context Switch
When CPU switches to another process, the system must

save the state of the old process and load the saved state for the new process. This task is known as context switch. Context-switch time is overhead; the system does no useful work while switching. Time dependent on hardware support and varies from machine to machine.

Operating System Concepts

4.17

Silberschatz, Galvin and Gagne 2002

Process Creation
A process may create several new processes, the creating

process is called Parent process, while the created process is called a child process, forming a tree of processes.
Resource sharing Parent and children share all resources. Children share subset of parents resources. Parent and child share no resources. In addition to resources, initialization data is also passed

from the parent process to the child process.


Execution Parent and children execute concurrently. Parent waits until children terminate.
Operating System Concepts
4.18

Silberschatz, Galvin and Gagne 2002

Process Termination
Process executes last statement and asks the operating

system to delete it by calling exit system call. Output data from child to parent (via wait). Process resources are deallocated by operating system. Parent may terminate execution of children processes using abort system call. Parent terminate the child process if: Child has exceeded allocated resources. Task assigned to child is no longer required. Parent is exiting. Operating system does not allow child to continue if its parent terminates.This is called Cascading termination.
Operating System Concepts
4.19

Silberschatz, Galvin and Gagne 2002

Vous aimerez peut-être aussi