# Operating System (CH 2)
# Operating System (CH 2)
By
Fikadu M.
[email protected]
Chapter Two
Processes and Process
Management
Lecture 2: Processes and Process Management 2/ 11/ 202
Outline
3
🠶 Process Concept
🠶 Process control block (PCB)
🠶 Thread concept
🠶 Process Scheduling
🠶 Inter-process Communication
🠶 Deadlock
🠶 Process Table
🠶The OS maintains pointers to each process’s PCB in a system wide
or per-user process table
🠶Allows for quick access to PCBs
🠶When a process is terminated, the OS removes the process from the
process table and frees all of the process’s resources
🠶 A process includes:
• program counter
• stack
• data section
The main reason for having threads is that in many applications, multiple
activities are going on at once. Some of these may block from time
to time. By decomposing such an application into multiple sequential
threads that run in quasi-parallel, the programming model becomes
simpler.
A second argument for having threads is that since they are lighter weight
than processes, they are easier (i.e., faster) to create and destroy than
processes.
A third reason for having threads is also a performance argument.
🠶 Thread Example
As soon as the sentence is deleted from page 1, the interactive thread tells the
reformatting thread to reformat the whole book.
Meanwhile, the interactive thread continues to listen to the keyboard and mouse
and responds to simple commands like scrolling page 1 while the other thread is
computing madly in the background.
🠶 The third thread can handle the disk backups without interfering
with the other two.
🠶running _blocked
Process is waiting for some event to occur (for I/O operation to
complete, etc.)
🠶blocked _ ready
Whatever event the process was waiting on has occurred
🠶Running _ Terminated
When the process completed
Back in the old days of batch systems with input in the form of card
images on a magnetic tape, the scheduling algorithm was simple: just
runs the next job on the tape.
Third, when a process blocks on I/O, or for some other reason, another
process has to be selected to run. Sometimes the reason for blocking may play
a role in the choice.
New Ready
Blocked/suspend Ready/suspend
Ready/suspend
Ready Blocked/suspend
Blocked
Lecture 2: Processes and Process Management 2/ 11/ 202
Cont’d
34
…
3. Short-term scheduling
The decision of which ready process to execute next
dispatched)
Ready _Running
Example:
🠶 Consider performance of FCFS algorithm for three compute-bound processes.
Throughput? 30 / 3 = 10.
1. Selection function
It determines which process, among ready processes, is selected for execution
It may be based on:
Priority
Resource requirement
Execution behavior: time spent in system so far(waiting and executing),time
spent in execution so far, total service time required by the process
1. Preemptive
The strategy of allowing processes that is logically runnable to be temporarily suspended and be
moved to the ready state.
Events that may result pre-emption are arrived of new processes, occurrence of an interrupt
that moves blocked process to ready state and clock interrupt
2. Non-preemptive
Run to completion method: once a process is in running state ,it continues to execute until it terminates
or
blocks itself to wait for some event
Simple and easy to implement
Throughput =3/30=1/10
Response time
Tr/Ts
Response time 0 0 99 99
Throughput =4/202
Case i. SJFS
Process p3 p2 p1
Turn around time 3 6 30
Response time 0 3 6
Average response time =(0+3+6)/3=3
Average turn around time =(3+6+30)/3=13
Throughput =3/30
P1 P3 P2 P4
0 3 7 8 12
16
P3 P2 P4 P1
0 1 5 10 16
P1 P2 P3 P2 P4 P1
0 11 16
2 4 5 7
process p1 p2 p3 p4 p5
arrival time(Ta) 0 2 4 6 8
service time(Ts) 3 6 4 5 2
turn around time(Tr) 3 13 4 14 2
response time 0 1 0 9 0
process p1 p2 p3 p4 p5
priority 2 4 5 3 1
service time(Ts) 3 6 4 5 2
turn around time 18 10 4 15 20
response time 15 4 0 10 18
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3
🠶 FCFS simple but causes short jobs to wait for long jobs.
🠶 SJF is optimal giving shortest waiting time but need to know length of next burst.
🠶 SJF is a type of priority scheduling - may suffer from starvation - prevent using
aging
1. Race condition
3. No process running outside its critical region may block other processes.
🠶 Not only does this approach waste CPU time, but it can also have unexpected
effects.
🠶 This was the situation in 1965, when E. W. Dijkstra (1965) suggested using an
integer variable to count the number of wakeups saved for future use.
🠶 In his proposal, a new variable type, which he called a semaphore, was introduced.
🠶 A semaphore could have the value 0, indicating that no wakeups were saved, or
some positive value if one or more wakeups were pending.
🠶 Example
🠶 No Preemption -
🠶 If a process that is holding some resources requests another resource that cannot
be immediately allocated to it, then all resources currently being held are
released.
🠶 Circular Wait - impose a total ordering of all resource types, and require
that each
🠶 process requests resources in an increasing order of enumeration.
🠶 How long process has computed, and how much longer to completion.
🠶 Resource Preemption
🠶 Selecting a victim - minimize cost.
🠶 Rollback - return to some safe state, restart process from that state.
🠶 Starvation - same process may always be picked as victim; include number
of rollback in cost factor.