Unit 2 Process & Thread
Unit 2 Process & Thread
Unit 2 Process & Thread
2
Processes and Programs
• What Is a Process?
• Relationships between Processes and Programs
• Child Processes
• Concurrency and Parallelism
3
What Is a Process?
13
Example: Process State Transitions
• A system contains two processes P1 and P2
15
Suspended Processes
• A kernel needs additional states to describe processes
suspended due to swapping
Process Context and the Process
Control Block
• Kernel allocates resources to a process and schedules
it for use of the CPU
– The kernel’s view of a process is comprised of the
process context and the process control block
Context Save, Scheduling, and
Dispatching
• Context save function:
– Saves CPU state in PCB, and saves information
concerning context
– Changes process state from running to ready
• Scheduling function:
– Uses process state information from PCBs to select a
ready process for execution and passes its id to
dispatching function
• Dispatching function:
– Sets up context of process, changes its state to running,
and loads saved CPU state from PCB into CPU
– Flushes address translation buffers used by MMU
Event Handling
• Events that occur during the operation of an OS:
1. Process creation event
2. Process termination event
3. Timer event
4. Resource request event
5. Resource release event
6. I/O initiation request event
Event Handling (continued)
• Events that occur during the operation of an OS
(continued):
7. I/O completion event
8. Message send event
9. Message receive event
10. Signal send event
11. Signal receive event
12. A program interrupt
13. A hardware malfunction event
21
Event Handling (continued)
• When an event occurs, the kernel must find the process
whose state is affected by it
– OSs use various schemes to speed this up
• E.g., event control blocks (ECBs)
P1 initiates I/O operation on d
Sharing, Communication and
Synchronization Between Processes
Signals
• A signal is used to notify an exceptional situation to a
process and enable it to attend to it immediately
– Situations and signal names/numbers defined in OS
• CPU conditions like overflows
• Conditions related to child processes
• Resource utilization
• Emergency communications from a user to a process
• Can be synchronous or asynchronous
• Handled by process-defined signal handler or OS
provided default handler
Example: Signal handling
Threads