MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2....
Transcript of MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2....
![Page 1: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/1.jpg)
MODERN OPERATING SYSTEMS
Third Edition
ANDREW S. TANENBAUM
Chapter 2Processes and Threads
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 2: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/2.jpg)
Figure 2-1. (a) Multiprogramming of four programs. (b) Conceptual model of four independent, sequential processes. (c) Only
one program is active at once.
The Process Model
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 3: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/3.jpg)
Events which cause process creation1. System initialization.2. Execution of a process creation system
call by a running process.3. A user request to create a new process.4. Initiation of a batch job.
Process Creation
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 4: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/4.jpg)
Events which cause process termination1. Normal exit (voluntary).2. Error exit (voluntary).3. Fatal error (involuntary).4. Killed by another process (involuntary).
Process Termination
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 5: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/5.jpg)
Figure 2-2. A process can be in running, blocked, or ready state. Transitions between these states are as shown.
Process States
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 6: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/6.jpg)
Figure 2-3. The lowest layer of a process-structured operating system handles interrupts and scheduling. Above that layer
are sequential processes.
Implementation of Processes (1)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 7: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/7.jpg)
Figure 2-4. Some of the fields of a typical process table entry.
Implementation of Processes (2)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 8: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/8.jpg)
Figure 2-5. Skeleton of what the lowest level of the operating system does when an interrupt occurs.
Implementation of Processes (3)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 9: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/9.jpg)
Figure 2-6. CPU utilization as a function of the number of processes in memory.
Modeling Multiprogramming
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 10: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/10.jpg)
Figure 2-7. A word processor with three threads.
Thread Usage (1)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 11: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/11.jpg)
Figure 2-8. A multithreaded Web server.
Thread Usage (2)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 12: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/12.jpg)
Figure 2-9. A rough outline of the code for Fig. 2-8. (a) Dispatcher thread. (b) Worker thread.
Thread Usage (3)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 13: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/13.jpg)
Figure 2-10. Three ways to construct a server.
Thread Usage (4)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 14: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/14.jpg)
Figure 2-11. (a) Three processes each with one thread. (b) One process with three threads.
The Classical Thread Model (1)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 15: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/15.jpg)
Figure 2-12. The first column lists some items shared by all threads in a process. The second one lists some items private
to each thread.
The Classical Thread Model (2)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 16: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/16.jpg)
Figure 2-13. Each thread has its own stack.
The Classical Thread Model (3)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 17: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/17.jpg)
Figure 2-14. Some of the Pthreads function calls.
POSIX Threads (1)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 18: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/18.jpg)
Figure 2-15. An example program using threads.
POSIX Threads (2)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
. . .
![Page 19: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/19.jpg)
Figure 2-15. An example program using threads.
POSIX Threads (3)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
. . .
![Page 20: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/20.jpg)
Figure 2-16. (a) A user-level threads package. (b) A threads package managed by the kernel.
Implementing Threads in User Space
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 21: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/21.jpg)
Figure 2-17. Multiplexing user-level threads onto kernel-level threads.
Hybrid Implementations
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 22: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/22.jpg)
Figure 2-18. Creation of a new thread when a message arrives. (a) Before the message arrives. (b) After the message arrives.
Pop-Up Threads
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 23: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/23.jpg)
Figure 2-19. Conflicts between threads over the use of a global variable.
Making Single-Threaded Code Multithreaded (1)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 24: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/24.jpg)
Figure 2-20. Threads can have private global variables.
Making Single-Threaded Code Multithreaded (2)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 25: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/25.jpg)
Figure 2-21. Two processes want to access shared memory at the same time.
Race Conditions
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 26: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/26.jpg)
Conditions required to avoid race condition1. No two processes may be simultaneously
inside their critical regions.2. No assumptions may be made about speeds
or the number of CPUs.3. No process running outside its critical region
may block other processes.4. No process should have to wait forever to
enter its critical region.
Critical Regions (1)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 27: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/27.jpg)
Figure 2-22. Mutual exclusion using critical regions.
Critical Regions (2)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 28: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/28.jpg)
Proposals for achieving mutual exclusion
1. Disabling interrupts2. Lock variables3. Strict alternation4. Peterson's solution5. The TSL instruction
Mutual Exclusion with Busy Waiting
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 29: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/29.jpg)
Figure 2-23. A proposed solution to the critical region problem. (a) Process 0. (b) Process 1. In both cases, be sure to note
the semicolons terminating the while statements.
Strict Alternation
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 30: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/30.jpg)
Figure 2-24. Peterson’s solution for achieving mutual exclusion.
Peterson's Solution
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 31: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/31.jpg)
Figure 2-25. Entering and leaving a critical region using the TSL instruction.
The TSL Instruction (1)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 32: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/32.jpg)
Figure 2-26. Entering and leaving a critical region using the XCHG instruction.
The TSL Instruction (2)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 33: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/33.jpg)
Figure 2-27. The producer-consumer problem with a fatal race condition.
The Producer-Consumer Problem (1)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
. . .
![Page 34: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/34.jpg)
Figure 2-27. The producer-consumer problem with a fatal race condition.
The Producer-Consumer Problem (2)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
. . .
![Page 35: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/35.jpg)
Figure 2-28. The producer-consumer problem using semaphores.
Semaphores (1)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
. . .
![Page 36: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/36.jpg)
Figure 2-28. The producer-consumer problem using semaphores.
Semaphores (2)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
. . .
![Page 37: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/37.jpg)
Figure 2-29. Implementation of mutex lock and mutex unlock.
Mutexes
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 38: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/38.jpg)
Figure 2-30. Some of the Pthreads calls relating to mutexes.
Mutexes in Pthreads (1)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 39: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/39.jpg)
Figure 2-31. Some of the Pthreads calls relating to condition variables.
Mutexes in Pthreads (2)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 40: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/40.jpg)
Figure 2-32. Using threads to solve the producer-consumer problem.
Mutexes in Pthreads (3)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
. . .
![Page 41: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/41.jpg)
Figure 2-32. Using threads to solve the producer-consumer problem.
Mutexes in Pthreads (4)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
. . .
. . .
![Page 42: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/42.jpg)
Figure 2-32. Using threads to solve the producer-consumer problem.
Mutexes in Pthreads (5)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
. . .
![Page 43: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/43.jpg)
Figure 2-33. A monitor.
Monitors (1)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 44: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/44.jpg)
Figure 2-34. An outline of the producer-consumer problem with monitors. Only one monitor procedure at a time is active. The
buffer has N slots.
Monitors (2)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 45: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/45.jpg)
Figure 2-34. An outline of the producer-consumer problem with monitors. Only one monitor procedure at a time is active. The
buffer has N slots.
Monitors (3)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 46: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/46.jpg)
Figure 2-35. A solution to the producer-consumer problem in Java.
Message Passing (1)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
. . .
![Page 47: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/47.jpg)
Figure 2-35. A solution to the producer-consumer problem in Java.
Message Passing (2)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
. . .
. . .
![Page 48: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/48.jpg)
Figure 2-35. A solution to the producer-consumer problem in Java.
Message Passing (3)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
. . .
![Page 49: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/49.jpg)
Figure 2-36. The producer-consumer problem with N messages.
Producer-Consumer Problem with Message Passing (1)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
. . .
![Page 50: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/50.jpg)
Figure 2-36. The producer-consumer problem with N messages.
Producer-Consumer Problem with Message Passing (2)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
. . .
![Page 51: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/51.jpg)
Figure 2-37. Use of a barrier. (a) Processes approaching a barrier. (b) All processes but one blocked at the barrier. (c) When the last process arrives at the barrier, all of them are let through.
Barriers
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 52: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/52.jpg)
Figure 2-38. Bursts of CPU usage alternate with periods of waiting for I/O. (a) A CPU-bound process. (b) An I/O-bound process.
Scheduling – Process Behavior
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 53: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/53.jpg)
1. Batch2. Interactive3. Real time
Categories of Scheduling Algorithms
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 54: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/54.jpg)
Figure 2-39. Some goals of the scheduling algorithm under different circumstances.
Scheduling Algorithm Goals
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 55: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/55.jpg)
• First-come first-served• Shortest job first• Shortest remaining Time next
Scheduling in Batch Systems
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 56: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/56.jpg)
Figure 2-40. An example of shortest job first scheduling. (a) Running four jobs in the original order. (b) Running them
in shortest job first order.
Shortest Job First
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 57: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/57.jpg)
• Round-robin scheduling• Priority scheduling• Multiple queues• Shortest process next• Guaranteed scheduling• Lottery scheduling• Fair-share scheduling
Scheduling in Interactive Systems
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 58: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/58.jpg)
Figure 2-41. Round-robin scheduling. (a) The list of runnable processes. (b) The list of runnable
processes after B uses up its quantum.
Round-Robin Scheduling
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 59: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/59.jpg)
Figure 2-42. A scheduling algorithm with four priority classes.
Priority Scheduling
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 60: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/60.jpg)
Figure 2-43. (a) Possible scheduling of user-level threads with a 50-msec process quantum and threads that run 5 msec per
CPU burst.
Thread Scheduling (1)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 61: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/61.jpg)
Figure 2-43. (b) Possible scheduling of kernel-level threads with the same characteristics as (a).
Thread Scheduling (2)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 62: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/62.jpg)
Figure 2-44. Lunch time in the Philosophy Department.
Dining Philosophers Problem (1)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 63: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/63.jpg)
Figure 2-45. A nonsolution to the dining philosophers problem.
Dining Philosophers Problem (2)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
![Page 64: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/64.jpg)
Figure 2-46. A solution to the dining philosophers problem.
Dining Philosophers Problem (3)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
. . .
![Page 65: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/65.jpg)
Figure 2-46. A solution to the dining philosophers problem.
Dining Philosophers Problem (4)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
. . .
. . .
![Page 66: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/66.jpg)
Figure 2-46. A solution to the dining philosophers problem.
Dining Philosophers Problem (5)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
. . .
![Page 67: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/67.jpg)
Figure 2-47. A solution to the readers and writers problem.
The Readers and Writers Problem (1)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
. . .
![Page 68: MODERN OPERATING SYSTEMS · Events which cause process creation 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to](https://reader031.fdocuments.in/reader031/viewer/2022020304/5bb23ff409d3f2e82b8c3ca5/html5/thumbnails/68.jpg)
Figure 2-47. A solution to the readers and writers problem.
The Readers and Writers Problem (2)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
. . .