OSDI Lecture 02
OSDI Lecture 02
01/03/2025 2
PROCESS
Process Management
A program – a passive entity - does nothing unless its instructions
are executed by CPU. When a program is running then it is called as
process.
A process – an active entity with a PC specifying the next
instruction to execute - is a program in execution.
A process needs certain resources, including CPU time, memory,
files, and I/O devices to accomplish its task. The execution of
process must progress sequentially.
Process is not a program. Process is not a program.
01/03/2025 3
TASK MANAGER
01/03/2025 4
PROGRAM VS. PROCESS
01/03/2025 5
TYPE OF PROCESSES
1. CPU bound processes- spends more time doing computations
few very long CPU bursts
2. I/O bound processes-spends more time doing I/O than
computations, many short CPU bursts CPU-bound process
01/03/2025 6
PROCESS CONTROL
BLOCK(PCB)
Process control block (PCB) is a data structure which is associated with any
process and provides all the complete information about that process.
1. Process state – running, waiting, etc
2. Program counter – location of instruction to next execute
3. CPU registers – contents of all process-centric registers
4. CPU scheduling information- priorities, scheduling queue pointers
5. Memory-management information – memory allocated to the process
6. Accounting information – CPU used, clock time elapsed since start, time
limits
7. I/O status information – I/O devices allocated to process, list of open files
01/03/2025 7
PROCESS CONTROL
BLOCK(PCB)
01/03/2025 8
CONTEXT SWITCH
In computing, a context switch is the process of storing the state of
a process or of a thread, so that it can be restored and execution
resumed from the same point later.
This allows multiple processes to share a single CPU, and is an
essential feature of a multitasking operating system.
Context of a process represented in the PCB Context-switch time is
overhead.
To switch between processes, the OS must:
a) Save the context of the currently executing process (if any), and
b) Restore the context of that being resumed.
01/03/2025 9
CONTEXT SWITCH
01/03/2025 10
DISPATCHER
Dispatcher module gives control of the CPU to the process selected
by the short-term scheduler.
Dispatch latency: time it takes for the dispatcher to stop one
process and start another running. The function involves :
1. Switching context
2. Switching to user mode
3. Jumping to the proper location in the user
01/03/2025 11
SCHEDULING QUEUES
Job queue – set of all processes in the hard disk
Ready queue – set of all processes residing in main memory, ready
and waiting to execute on CPU
Waiting (Device) queues – set of processes waiting for an I/O device
01/03/2025 12
MOVING BETWEEN QUEUES
01/03/2025 13
QUEUES IN OS
01/03/2025 14
SCHEDULERS IN OS
Short-term scheduler (or CPU scheduler) selects which process
should be executed next and allocates CPU
Long-term scheduler (or job scheduler) selects which processes
should be brought into the ready queue. The long-term scheduler
controls the degree of multiprogramming.
Degree of multiprogramming: The number of processes in the
memory.
Medium-term scheduler can be added if degree of multiple
programming needs to decrease. Remove process from memory,
store on disk, and bring back in from disk to continue execution:
swapping.
01/03/2025 15
SWAPPING
01/03/2025 16
PROCESS STATES
As a process executes, it changes state
new: The process is being created
running: Instructions are being executed
waiting: The process is waiting for some event to occur
ready: The process is waiting to be assigned to a processor
terminated: The process has finished execution
01/03/2025 17
DIAGRAM OF PROCESS
STATE (5 STATES)
01/03/2025 18
DIAGRAM OF PROCESS
STATE (7 STATES)
Additional two states are Ready/Suspended and
Blocked/Suspended. These states are in the hard disk since ready
queue and waiting queue can be full the processes will be
suspended and swap out.
01/03/2025 19
THE OS IS RESPONSIBLE
FOR THE FOLLOWING:
1. Schedule the processes.
2. Creation and deletion of user and system processes.
3. Suspension and resumption of processes.
4. Provision of mechanisms for process communications.
5. Provision of mechanisms for deadlock handling.
01/03/2025 20
DEADLOCK
Deadlock is a situation where a set of processes are blocked
because each process is holding a resource and waiting for another
resource acquired by some other process.
01/03/2025 21
PROCESS CREATION
Parent process creates children processes, which, in turn create other processes, forming a tree of processes
in Unix use system call fork( ).
A process needs resources (CPU time, memory, files, I/O).
When a process creates a sub-process:
For resources
Parent and children may share all resources.
Children may share subset of parent’s resources.
Parent and children may share no resources.
For execution
Parent and children may execute concurrently.
Parent may wait until children terminate.
For address space
Child process address space is duplicate of parent’s.
Child has a program loaded into it. -> in UNIX: use execlp().
01/03/2025 22
PROCESS CREATION.
01/03/2025 23
C PROGRAM FORKING A SEPARATE
PROCESS int main()
pid = fork();
exit(-1);
wait (NULL);
exit(0);
}
01/03/2025 24
}
QUESTIONS AND ANSWERS
Thank
01/03/2025
You 25