03 - Processes
03 - Processes
Lecture - 3
Soumyabrata DEV
https://soumyabrata.dev/
Processes
2
Process
3
Process
5
Process or Program
6
Multiple Processes
7
Process in Operating System
8
Process States
9
Process States
10
Process Control Block (PCB)
11
Contents of a Process Control Block (PCB):
1. Process State:
• This field indicates the current state of the process, such as running,
ready, waiting, or terminated. It helps the operating system understand
what the process is currently doing and how it should be managed.
2. Process ID (PID):
• A unique identifier assigned to each process in the system. This allows
the operating system to distinguish between different processes.
3. Program Counter (PC):
• The address of the next instruction to be executed within the process's
program code. This is essential for resuming execution after a context
switch.
12
Contents of a Process Control Block (PCB):
4. Registers:
• PCB typically includes a set of CPU registers that store the process's context, including
general-purpose registers, program counter, stack pointer, and more. Saving and restoring
these registers is a crucial part of context switching.
5. Stack Pointer (SP):
• Points to the top of the process's execution stack, which is used for function calls and
storing local variables. The SP helps maintain the execution context.
6. Memory Management Information:
• Information about the memory allocated to the process, including the base and limit
registers. This helps the operating system protect processes from accessing each other's
memory areas.
13
Contents of a Process Control Block (PCB):
7. Open File Pointers:
• A list of files or I/O devices that the process has opened or is currently using. This
ensures proper resource management and access control
8. Priority and Scheduling Information:
• Information related to the process's priority in a scheduling algorithm, time
spent executing, and other scheduling-related data.
9. Accounting Information:
• Data on resource usage, such as CPU time consumed, file system usage, and
more. This information can be useful for performance analysis and billing.
14
Process Switching
15
Overhead in Context Switch
16
Overhead in Context Switch
17
Process Creation
• System boot
18
Process Termination
19
Process Termination
20
Child Processes
21
Process Tree
init
pid = 1
emacs tcsch
ps
pid = 9204 pid = 4005
pid = 9298
22
Child Processes
23
Example (Unix)
• The child process must have a new PID, and will have
different pointers for its parent/child processes
25
Interprocess Communication (IPC)
26
Independent Processes
27
Properties of Independent Processes
28
Cooperative Processes
30
Properties of Cooperative Processes
31
Why Allow Processes to Cooperate?
• Convenience
• We can do things like editing a file at the same time it is
being printed
32
Why Allow Processes to Cooperate?
33
Issues with Processes
Definition of Threads
• A thread is the smallest unit of execution within a process. Threads
share the same program code and data space but have their own
stack and registers.
35
Motivation for Threads
36
Motivation for Threads
37
Motivation for Threads
38
Solution: Threads
39
File Server Example
40
File Server Example
41
Threads
42
Concurrency in some existing OS
43
Threads & Processes
44
Threads & Processes
• Interrupt vectors
• Stack
• State
• Child threads
45
Threads & Processes
• Threads are cheap to create (no need to allocate PCB, new address
space)
46
Thread Implementations
47
Threads in user space
• per process thread table: process decides which of its threads to run
when it is running
48
Advantages of Threads in user space
49
Disadvantage of Threads in user space
50
Threads in kernel space
• In this case threads (and not processes) are the smallest units of
scheduling
51
Advantages of Threads in kernel space
• Better interactivity
52
Disadvantages of Threads in kernel space
• Less portable
53
Threads in both levels
54
Thank you!
55