0% found this document useful (0 votes)
56 views13 pages

Process Concept Process Concept (Cont.) : Processes Processes Processes Processes

This document discusses processes and process scheduling. It defines a process as a program in execution. Processes go through various states like new, running, waiting, ready and terminated. A process control block (PCB) stores information about a process like its state, program counter and scheduling information. Concurrency can be achieved through processes sharing physical and logical resources. The operating system uses queues and schedulers to manage processes and allocate CPU time between ready processes.

Uploaded by

api-19794302
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views13 pages

Process Concept Process Concept (Cont.) : Processes Processes Processes Processes

This document discusses processes and process scheduling. It defines a process as a program in execution. Processes go through various states like new, running, waiting, ready and terminated. A process control block (PCB) stores information about a process like its state, program counter and scheduling information. Concurrency can be achieved through processes sharing physical and logical resources. The operating system uses queues and schedulers to manage processes and allocate CPU time between ready processes.

Uploaded by

api-19794302
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Processes

Process Concept
Process Concept
(cont.)
• An operating system • Process – a program in
executes a variety of execution; process execution
programs: must progress in sequential
– Batch system – jobs
fashion
– Time-shared systems – user • A process includes:
programs or tasks – program counter
• Textbook uses the terms job – stack
and process almost – data section
interchangeably
3 4

Process State Process State (cont.)


• As a process executes, it – ready:
ready The process is waiting to
changes state be assigned to a process
– new:
new The process is being created – terminated:
terminated The process has
finished execution
– running:
running Instructions are being
executed
– waiting:
waiting The process is waiting
for some event to occur

5 6

1
Diagram of Process Process Control Block
State (PCB)
Info. associated with each process
• Process state
• Program counter
• CPU registers
• CPU scheduling information
• Memory-management information
• Accounting information
• I/O status information
7 8

Process Control Block CPU Switch From


(PCB) Process to Process

9 10

Concurrent Processes Process Creation


• Physical Resource Sharing • Parent process create children
• Logical Resource Sharing processes, which, in turn
• Computation Speed Up create other processes, forming
a tree of processes
• Modularity
• Convenience

11 12

2
Process Creation Process Creation
(cont.) (cont.)
• Resource sharing • Execution
– Parent and children share all – Parent and children execute
resources concurrently
– Children share subset of parent’s – Parent waits until children
resources terminate
– Parent and child share no
resources

13 14

C Program Forking C Program Forking


Separate Process Separate Process (cont.)
else if (pid == 0) { /* child process
#include <stdio.h>
*/
#include <unistd.h>
int main(int argc, char *argv[]) execlp("/bin/ls","ls",NULL);
{ }
int pid; else { /* parent process */
/* fork another process */ /* parent will wait for the
child to complete */
pid = fork();
wait(NULL);
if (pid < 0) { /* error occurred */
fprintf(stderr, "Fork Failed"); printf("Child Complete");
exit(0);
exit(-1);
}
} 15 16
}

Processes Tree on
a UNIX System Process Termination
• Process executes last statement
and asks the operating system
to decide it (exit
exit)
exit
– Output data from child to parent
(via wait)
wait
– Process’ resources are
deallocated by operating system
• Parent may terminate execution
of children processes (abort
abort)
abort
17 18

3
Process Termination Relation Bet.
(cont.) Processes
– Child has exceeded allocated • Independent process cannot
resources affect or be affected by the
– Task assigned to child is no execution of another process
longer required
• Cooperating process can affect
– If parent is exiting
or be affected by the execution
• Some operating system do not allow
child to continue if its parent of another process
terminates
– All children terminated - cascading
termination

19 20

Threads Threads (cont.)


• A thread (or lightweight • A thread shares with its peer
process) is a basic unit of CPU threads its:
utilization; it consists of: – code section
– program counter – data section
– operating-system resources
– register set
collectively know as a task.
– stack space
• A traditional or heavyweight
process is equal to a task with
one thread
21 22

Multiple Threads
Threads (Cont.)
within a Task
• In a multiple threaded task,
while one server thread is
blocked and waiting, a
second thread in the same
task can run.

23 24

4
Process Scheduling Process Scheduling
Queues Queues (cont.)
• Job queue – set of all • Device queues – set of
processes in the system processes waiting for an I/O
• Ready queue – set of all device
processes residing in main • Process migration between the
memory, ready and waiting to various queues
execute

25 26

Ready Queue And Various Representation of


I/O Device Queues Process Scheduling

27 28

Addition of Medium
Schedulers
Term Scheduling

• Long-term scheduler (or job


scheduler) – selects which
processes should be brought
into the ready queue
• Short-term scheduler (or CPU
scheduler) – selects which
process should be executed next
and allocates CPU
29 30

5
Schedulers (Cont.) Schedulers (cont.)
• Short-term scheduler is invoked • Processes can be described as
very frequently (milliseconds) either:
⇒ (must be fast) – I/O-bound process – spends more
• Long-term scheduler is invoked time doing I/O than computations,
many short CPU bursts
very infrequently (seconds,
minutes) ⇒ (may be slow) – CPU-bound process – spends more
time doing computations; few very
• The long-term scheduler long CPU bursts
controls the degree of
multiprogramming
31 32

Context Switch CPU Scheduling


• When CPU switches to another
• Basic Concepts
process, the system must save
the state of the old process and • Scheduling Criteria
load the saved state for the new • Scheduling Algorithms
process • Multiple-Processor
• Context-switch time is overhead; Scheduling
the system does no useful work • Real-Time Scheduling
while switching
• Time dependent on HW support
33 34

CPU Scheduling
Basic Concepts
(cont.)
• Thread Scheduling
• Operating Systems Examples • Maximum CPU utilization
obtained with multiprogramming
• Java Thread Scheduling
• CPU–I/O Burst Cycle – Process
• Algorithm Evaluation execution consists of a cycle
of CPU execution and I/O wait
• CPU burst distribution

35 36

6
Alternating Sequence of
CPU And I/O Bursts CPU Scheduler
• Selects from among the
processes in memory that are
ready to execute, and allocates
the CPU to one of them

37 38

CPU Scheduler (cont.) CPU Scheduler (cont.)


• CPU scheduling decisions may • Scheduling under 1 and 4 is
take place when a process: nonpreemptive
1.Switches from running to waiting • All other scheduling is
state preemptive
2.Switches from running to ready
state
3.Switches from waiting to ready
4.Terminates

39 40

Dispatcher Dispatcher (cont.)


• Dispatcher module gives control • Dispatch latency – time it
of the CPU to the process takes for the dispatcher to
selected by the short-term stop one process and start
scheduler; this involves: another running
– switching context
– switching to user mode
– jumping to the proper location in
the user program to restart that
program
41 42

7
Scheduling Criteria
Scheduling Criteria
(cont.)
• Waiting time – amount of time a
• CPU utilization – keep the process has been waiting in the
CPU as busy as possible ready queue
• Throughput – # of processes • Response time – amount of time
that complete their it takes from when a request
was submitted until the first
execution per time unit
response is produced, not
• Turnaround time – amount of output (for time-sharing
time to execute a environment)
particular process
43 44

First-Come, First-Served
Optimization Criteria (FCFS) Scheduling
ProcessBurst Time
• Max CPU utilization
P1 24
• Max throughput
P2 3
• Min turnaround time P3 3
• Min waiting time • Suppose that the processes
• Min response time arrive in the order: P1 , P2 , P3
The Gantt Chart for the schedule
is:
P1 P2 P3

0 24 27 30
45 46

FCFS Scheduling FCFS Scheduling


(Cont.) (Cont.)
Suppose that the processes
• Waiting time for P1 = 0; P2 = arrive in the order
24; P3 = 27 P2 , P3 , P1
• Average waiting time: (0 + 24 • The Gantt chart for the
+ 27)/3 = 17 schedule is:
P2 P3 P1

0 3 6 30

47 48

8
FCFS Scheduling Shortest-Job-First
(Cont.) (SJR) Scheduling
• Waiting time for P1 = 6; P2 = 0; • Associate with each process the
P3 = 3 length of its next CPU burst.
• Average waiting time: (6 + 0 Use these lengths to schedule
+ 3)/3 = 3 the process with the shortest
• Much better than previous case time
• Convoy effect short process
behind long process

49 50

Shortest-Job-First Shortest-Job-First
(SJR) Scheduling (SJR) Scheduling
(cont.) (cont.)
• Two schemes:
– preemptive – if a new process
– nonpreemptive – once CPU given to arrives with CPU burst length
the process it cannot be less than remaining time of
preempted until completes its CPU current executing process,
burst preempt. This scheme is know as
the
Shortest-Remaining-Time-First
(SRTF)
• SJF is optimal – gives minimum
average waiting time for a
given set of processes
51 52

Example of Non-
Example of Non-
Preemptive SJF
Preemptive SJF
(cont.)
ProcessArrival Time Burst Time
P1 0.0 7 • SJF (non-preemptive)
P2 2.0 4
P1 P3 P2 P4
P3 4.0 1
P4 5.0 4 0 3 7 8 12 16

• Average waiting time = (0 + 6 +


3 + 7)/4 - 4

53 54

9
Example of Preemptive Example of Preemptive
SJF SJF (cont.)
ProcessArrival Time Burst Time
P1 0.0 7 • SJF (preemptive)
P2 2.0 4
P1 P2 P3 P2 P4 P1
P3 4.0 1
0 2 4 5 7 11 16
P4 5.0 4

• Average waiting time = (9 + 1 +


0 +2)/4 - 3

55 56

Determining Length of Prediction of the Length


Next CPU Burst of the Next CPU Burst
• Can only estimate the length
• Can be done by using the length
of previous CPU bursts, using
exponential averaging
1. t n = actual lenght of n th CPU burst
2. τ n +1 = predicted value for the next CPU burst
3. α , 0 ≤ α ≤ 1
4. Define :
τ n =1 = α t n + (1 − α )τ n . 57 58

Examples of Examples of
Exponential Averaging Exponential Averaging
(cont.)
• α =0
– τn+1 = τn • If we expand the formula, we
– Recent history does not count get:
τn+1 = α tn+(1 - α) α tn -1 + …
• α =1 +(1 - α )j α tn -1 + …
– τn+1 = tn +(1 - α )n=1 tn τ0
– Only the actual last CPU burst
• Since both α and (1 - α) are
counts
less than or equal to 1, each
successive term has less weight
59
than its predecessor 60

10
Priority Scheduling
Priority Scheduling
(cont.)
• A priority number (integer) is • SJF is a priority scheduling
associated with each process where priority is the predicted
next CPU burst time
• The CPU is allocated to the
process with the highest • Problem ≡ Starvation – low
priority processes may never
priority (smallest integer ≡ execute
highest priority)
• Solution ≡ Aging – as time
– Preemptive progresses increase the
– nonpreemptive priority of the process
61 62

Round Robin (RR)


Round Robin (RR)
(cont.)
• Each process gets a small unit • If there are n processes in the
ready queue and the time
of CPU time (time quantum),
quantum is q, then each process
usually 10-100 milliseconds. gets 1/n of the CPU time in
After this time has elapsed, chunks of at most q time units
the process is preempted and at once. No process waits more
added to the end of the ready than (n-1)q time units.
queue. • Performance
– q large ⇒ FIFO
– q small ⇒ q must be large with
63
respect to context switch, 64
otherwise overhead is too high

Example of RR with Time Example of RR with


Quantum = 20 Time Quantum = 20
ProcessBurst Time • Typically, higher average
P1 53 turnaround than SJF, but better
P2 17 response
P3 68
P4 24
• The Gantt chart is:
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3

0 20 37 57 77 97 117 121 134 154 162

65 66

11
Time Quantum and Context Turnaround Time Varies
Switch Time With The Time Quantum

67 68

Multilevel Queue
Multilevel Queue
(cont.)
• Ready queue is partitioned into • Scheduling must be done between
separate queues: the queues
foreground (interactive) – Fixed priority scheduling; (i.e.,
background (batch) serve all from foreground then from
background). Possibility of
• Each queue has its own starvation.
scheduling algorithm – Time slice – each queue gets a
– foreground – RR certain amount of CPU time which it
– background – FCFS can schedule amongst its processes;
i.e., 80% to foreground in RR
69 – 20% to background in FCFS 70

Multilevel Queue Multilevel Feedback


Scheduling Queue
• A process can move between the
various queues; aging can be
implemented this way
• Multilevel-feedback-queue
scheduler defined by the
following parameters:

71 72

12
Multilevel Feedback Example of Multilevel
Queue (cont.) Feedback Queue
– number of queues • Three queues:
– scheduling algorithms for each – Q0 – time quantum 8 milliseconds
queue – Q1 – time quantum 16 milliseconds
– method used to determine when to – Q2 – FCFS
upgrade a process
– method used to determine when to
demote a process
– method used to determine which
queue a process will enter when
that process needs service
73 74

Example of Multilevel Multilevel Feedback


Feedback Queue (cont.) Queues
• Scheduling
– A new job enters queue Q0 which is
served FCFS. When it gains CPU,
job receives 8 milliseconds. If
it does not finish in 8
milliseconds, job is moved to
queue Q1.
– At Q1 job is again served FCFS and
receives 16 additional
milliseconds. If it still does
not complete, it is preempted and
75 76
moved to queue Q2.

Multiple-Processor
Real-Time Scheduling
Scheduling
• CPU scheduling more complex when • Hard real-time systems –
multiple CPUs are available required to complete a critical
• Homogeneous processors within a task within a guaranteed amount
multiprocessor of time
• Load sharing • Soft real-time computing –
• Asymmetric multiprocessing – requires that critical
only one processor accesses the processes receive priority over
system data structures, less fortunate ones
alleviating the need for data
77 78
sharing

13

You might also like