Download presentation
Presentation is loading. Please wait.
Published byNorman Freeman Modified over 9 years ago
1
Politecnico di Milano © 2001 William Fornaciari Operating System Processes Lecturer: William Fornaciari Politecnico di Milano fornacia@elet.polimi.itwww.elet.polimi.it/~fornacia
2
Processes© 2001 William Fornaciari- 2 - SUMMARY Process Concept (3 - 6) Process State (7 -21) Process Control Block(22-28) Operation on Processes(29-42)
3
Processes© 2001 William Fornaciari- 3 - MAJOR REQUIREMENTS OF AN OPERATING SYSTEM Interleave the execution of the number of processes to maximize processor utilization while providing reasonable response time Allocate resources to processes Support interprocess communication and user creation of processes
4
Processes© 2001 William Fornaciari- 4 - PROCESS CONCEPT Process = fundamental unit of computation Process – a program in execution; process execution must progress in sequential fashion. A process includes: program counter stack data section
5
Processes© 2001 William Fornaciari- 5 - PROCESS CATEGORIES An operating system executes a variety of processes : BATCH: Process receives all inputs at the beginning of operation, and produces output only at the end. There is no interaction. INTERACTIVE: Process performs work generally in short bursts and interacts with human users at a terminal. REAL-TIME: Process interacts with external devices or systems having timing constraints which must be met for correct operation. These categories are ordered by increasing criticality.
6
Processes© 2001 William Fornaciari- 6 - DIFFERENCE BETWEEN PROGRAM AND PROCESS Program: a static, algorithmic description, consists of instructions int main() { int i, prod=1; for(i=0; i<100; ++i) prod = prod*i; } Process: dynamic, consists of instruction executions
7
Processes© 2001 William Fornaciari- 7 - DISPATCHER Dispatcher functions : Program that moves the processor from one process to another Prevents a single process from monopolizing processor time
8
Processes© 2001 William Fornaciari- 8 - DISPATCHER : An Example (1) a = initial memory address of Process A b = initial memory address of Process B c = initial memory address of Process C o = initial memory address of Dispatcher program Dispatcher Process C Process B Process A a c b o Main MemoryProgram counter
9
Processes© 2001 William Fornaciari- 9 - DISPATCHER : An Example (2) Track of each process : a + 0 a + 1 a + 2 a + 3 a + 4 a + 5 a + 6 a + 7 a + 8 a + 9 a + 10 a + 11 c + 0 c + 1 c + 2 c + 3 c + 4 c + 5 c + 6 c + 7 c + 8 c + 9 c + 10 c + 11 b + 0 b + 1 b + 2 b + 3 Track of process: A B C Instruction b + 3 of process B calls an I/O request
10
Processes© 2001 William Fornaciari- 10 - DISPATCHER : An Example (3) Interleaved track of the processes Timeout : the operating system let the process to continue its execution at the most for 6 instructions cycles 1 a + 0 2 a + 1 3 a + 2 4 a + 3 5 a + 4 6 a + 5 ---------- Time out 7 o + 0 8 o + 1 9 o + 2 10 o + 3 11 o + 4 12 o + 5 13 b + 0 14 b + 1 15 b + 2 16 b + 3 ----------- I/O request 17 o + 0 18 o + 1 19 o + 2 20 o + 3 21 o + 4 22 o + 5 23 c + 0 24 c + 1 25 c + 2 26 c + 3 27 c + 4 28 c + 5 ----------- Time out 29 o + 0 30 o + 1 31 o + 2 32 o + 3 33 o + 4 34 o + 5 35 a + 6 36 a + 7 37 a + 8 38 a + 9 39 a + 10 40 a + 11 ------------ Time out 41 o + 0 42 o + 1 43 o + 2 44 o + 3 45 o + 4 46 o + 5 47 c + 6 48 c + 7 49 c + 8 50 c + 9 51 c + 10 52 c + 11 ------------- Time out
11
Processes© 2001 William Fornaciari- 11 - 1st IMPLEMENTATION : TWO STATE PROCESS MODEL (1) Not Running Processor Enter Dispatch Pause Exit State transition diagram Enter Queue of Not Running Processes DispatchExit Pause Queuing diagram
12
Processes© 2001 William Fornaciari- 12 - 1st IMPLEMENTATION : TWO STATE PROCESS MODEL (2) Two states : Running : instructions are being executed Not Running : the process is waiting to be assigned to a processor Greatest problem : Dispatcher cannot just select the process that has been in the queue the longest because it may be blocked
13
Processes© 2001 William Fornaciari- 13 - 2nd IMPLEMENTATION : FIVE STATE PROCESS MODEL (1) NewReadyRunningExit Blocked Admit Event Occurs Dispatch Release Time-out Event Wait
14
Processes© 2001 William Fornaciari- 14 - 2nd IMPLEMENTATION : FIVE STATE PROCESS MODEL (2) As a process executes, it changes state : Running : Instructions are being executed. Ready : The process is waiting to be assigned to a processor. Blocked : The process is waiting for some event to occur. New : The process is being created. Exit : The process has finished execution.
15
Processes© 2001 William Fornaciari- 15 - 2nd IMPLEMENTATION : An Example State of the processes about the execution track of slide ten
16
Processes© 2001 William Fornaciari- 16 - 2nd IMPLEMENTATION : SINGLE BLOCKED QUEUE Admit Ready Queue* Dispatch Time-out Event Wait Release Processor Blocked Queue* Event Occurs * The queues are FIFO (First In first Out )
17
Processes© 2001 William Fornaciari- 17 - 2nd IMPLEMENTATION : MULTIPLE BLOCKED QUEUES This system provides different queues for each event Admit Ready Queue Dispatch Time-out Release Processor Event 1 Wait Event 1 Queue Event 1 Occurs Event 2 Wait Event 2 Queue Event 2 Occurs
18
Processes© 2001 William Fornaciari- 18 - 3rd IMPLEMENTATION : SEVEN STATE PROCESS MODEL (1) New Admit Suspend Dispatch Time out Ready, suspend Ready Blocked Blocked, suspend Event Occurs Activate Event Occurs Activate Suspend RunningExit Event Wait
19
Processes© 2001 William Fornaciari- 19 - 3rd IMPLEMENTATION : SEVEN STATE PROCESS MODEL (2) Processor is faster than I/O so all processes could be waiting for I/O Swap these processes to disk to free up more memory Blocked state becomes suspend state when swapped to disk Two new states : Blocked-suspend : the swapped process is waiting for some event to occur Ready-suspend : the process is on the disk but isn’t waiting for events
20
Processes© 2001 William Fornaciari- 20 - PROCESS SUSPENSION : CAUSES Swap : the operating system has to free up more memory to load a process which is ready to be executed. Operating System Cause : the operating system can suspend a background process, an utility process or a process which is causing a problem. Interactive User request : a user want to suspend the execution of a program to debug or to use a resource.
21
Processes© 2001 William Fornaciari- 21 - PROCESS SUSPENSION : CAUSES Temporization : a process can be executed periodically and can be suspended while it is waiting the next time interval. Parent Process Request : a parent process can suspend the execution of a child to analyse or to modify a suspended process.
22
Processes© 2001 William Fornaciari- 22 - RESOURCE MANAGEMENT The operating system is the entity which manages the use of system resources by the processes P1 is being executed P2 is blocked because it’s waiting the I/O resource used by P1 Pn is loaded on the disk (suspended) P1PnP2 Processor I/O Main Memory I/O Virtual memory Computer Resources
23
Processes© 2001 William Fornaciari- 23 - PROCESS IMAGE STRUCTURE IN VIRTUAL MEMORY (1) Processor State Information Process Control Information Process Identification System Stack User Space (programs, datas) Shared Space PCB Processor State Information Process Control Information Process Identification System Stack User Space (programs, datas) Shared Space Processor State Information Process Control Information Process Identification System Stack User Space (programs, datas) Shared Space
24
Processes© 2001 William Fornaciari- 24 - PROCESS IMAGE STRUCTURE IN VIRTUAL MEMORY (2) PCB (Process Control Block) : structure of data used by the operating system to control the processes. System stack : each process has one or more than one LIFO stacks. This stack is used to register parameters and addresses of the system procedure calls. User space : the program which has to be executed and the structure of data the program is able to modify. Shared space : space shared by other processes.
25
Processes© 2001 William Fornaciari- 25 - PCB (1) Process Identification : Unique numeric identifier may be an index into the primary process table Parent process identifier who created this process User identifier who is responsible for the job
26
Processes© 2001 William Fornaciari- 26 - PCB (2) Process state informations : User-visible registers Control and status registers Program status word (PSW) : contains status information Example: the EFLAGS register on Pentium machines Process stack pointers
27
Processes© 2001 William Fornaciari- 27 - PCB (3.1) Process Control Information : additional information needed by the operating system to control and coordinate the various active processes scheduling and state information process state, priority, waited event data structuring relationship among processes interprocess communication flags, signals, messages
28
Processes© 2001 William Fornaciari- 28 - PCB (3.2) process privileges executable instructions, memory accesses memory management information about virtual memory used by the process resource ownership and utilization resources controlled by the process
29
Processes© 2001 William Fornaciari- 29 - FUNCTIONS OF THE KERNEL : PROCESS MANAGEMENT Process creation and termination Process scheduling and dispatching Process switching Process synchronization and support for inter- process communication Management of process control blocks
30
Processes© 2001 William Fornaciari- 30 - PROCESS CREATION STEPS 1Assign a unique process identifier and add a new entry in the main process table 2Allocate space for the process and for the process image 3Initialize process control block and set up the stack pointers 4Set up appropriate linkages Ex: add new process to linked list used for scheduling queue 5Other Ex : maintain an accounting file
31
Processes© 2001 William Fornaciari- 31 - CAUSES OF PROCESS CREATION Submission of a batch job User logs on Create to provide a service such as printing Spawned by an existing process
32
Processes© 2001 William Fornaciari- 32 - PROCESS TERMINATION Batch job issues Halt instruction User logs off Process executes a service request to terminate Error and fault conditions Steps : 1Process executes last statement and asks the operating system to decide it. 2Output data from child to parent. 3Process’ resources are deallocated by operating system.
33
Processes© 2001 William Fornaciari- 33 - REASONS FOR PROCESS TERMINATION (1) Normal completion Time limit exceeded Memory unavailable Memory bounds violation Protection error ex : write to read-only file Arithmetic error ex : division by 0
34
Processes© 2001 William Fornaciari- 34 - REASONS FOR PROCESS TERMINATION (2) Time overrun process waited longer than a specified maximum for an event I/O failure Invalid instruction ex : try to execute data Privileged instruction Data misuse ex : use of not initialized data
35
Processes© 2001 William Fornaciari- 35 - REASONS FOR PROCESS TERMINATION (3) Operating system intervention ex : deadlock occurs Parent terminates so child processes terminate Parent request
36
Processes© 2001 William Fornaciari- 36 - CPU SWITCH FROM PROCESS TO PROCESS
37
Processes© 2001 William Fornaciari- 37 - WHEN TO SWITCH A PROCESS Interrupts (caused by an external event) Clock :process has executed for the maximum allowable time slice I/O : other process is using this I/O resource Memory fault : memory address is in virtual memory so it must be brought into main memory Trap (caused by an internal event) error occurred : if the error is fatal, the trap may cause process to be moved to Exit state Supervisor call the process calls a kernel procedure
38
Processes© 2001 William Fornaciari- 38 - CHANGE OF EXECUTION MODE (Interrupt Cycle) 1Save the context of the program which is being executed 2Set the program counter on the address of the beginning of the interrupt handler program 3Change the user mode for the kernel mode The change of execution mode can happen without changing the process state
39
Processes© 2001 William Fornaciari- 39 - CHANGE OF PROCESS STATE 1Save context of processor including program counter and other registers 2Update the process control block with the new state and any accounting information 3Move process control block to appropriate queue - ready, blocked 4Select another process for execution 5Update the process control block of the process selected 6Update memory-management data structures 7Restore context of the selected process
40
Processes© 2001 William Fornaciari- 40 - EXECUTION OF THE OPERATING SYSTEM (1) Non Process Kernel (for traditional operating system) execute kernel outside of any process operating system code is executed as a separate entity that operates in privileged mode process concept is used only for the user programs Kernel P1P2Pn
41
Processes© 2001 William Fornaciari- 41 - EXECUTION OF THE OPERATING SYSTEM (2) Execution Within User Processes (for operating system of minicomputer) operating system software within context of a user process process executes in privileged mode when executing operating system code process can execute either a user program or an operating system program Process Change Function P1 Operating System Functions P2 Operating System Functions Pn Operating System Functions
42
Processes© 2001 William Fornaciari- 42 - EXECUTION OF THE OPERATING SYSTEM (3) Process-Based Operating System (for operating system of multicomputer) major kernel functions are separate processes a process is invoked by the operating system useful if some operating system services are executed by dedicated processors Process Change Function Pn U1UnU2 P2P1
43
Processes© 2001 William Fornaciari- 43 - REFERENCES Stallings W. Sistemi Operativi Jackson Libri Silberschatz A. Sistemi Operativi Addison-Wesley Tanenbaum A. I Moderni Sistemi Operativi Jackson Libri Web Material (see web page of the course)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.