Chapter 3
Chapter 3
Process Management
Important Terminologies
• Task
• When a program is requested for execution it is called a task.
• Before pressing enter key.
• Job
• When the OS checks the validity of the task by searching it in internal page
table, if present then it is said to be a valid job for further processing.
• Process
• The job is then loaded into computer memory, after memory allocation, the
program is set into execution.
• For example when we write following on the console,
• C:\>dir
• A task has been given to OS
• OS checks its validity by searching it into internal page table, if found, then
it is valid, become a job
• When it become a job, OS must load it into memory.
• Now this program under execution along with its environment is called a
Process.
Process Concept
• A process is a program in execution. It is a unit of work within
the system. Program is a passive entity while a process is an
active entity.
• One program can be several processes
• Consider multiple users executing the same program
• Process needs resources to accomplish its task
• CPU, memory, I/O, files
• Initialization data
• Process termination requires reclaim of any reusable resources
• Single-threaded process has one program counter specifying
location of next instruction to be executed
• Process executes instructions sequentially, one at a time, until
completion
• Multi-threaded process has one program counter per thread
• Typically system has many processes, some of user/user’s, some
of operating system that are running concurrently on one or
more CPUs
• Concurrency by multiplexing the CPUs among the processes/threads
Process Management Activities
• The operating system is responsible for the following
activities in connection with process management:
• Creating and deleting both user and system processes
• Suspending and resuming processes
• Providing mechanisms for process synchronization
• Providing mechanisms for process communication
• Providing mechanisms for deadlock handling
Process in Memory
• A process has multiple parts
• The program code, also called text section
• Current activity including program counter, processor registers
• Stack containing temporary data
• Function parameters, return addresses, local variables
• Data section containing global variables
• Heap containing memory dynamically allocated during run time
Process State
• As a process executes, it changes the state
• Ready: The process is waiting to be assigned to a
processor
• Running: Instructions are being executed
Example
Time Instant P1 P2
0 Running Ready
10 Ready Running
20 Running Ready
30 Ready Running
40 Running Ready
50 Ready Running
60 Running Ready
70 - Running
Class Exercise
Example
Process Burst Time Start/Arrival Time
P1 30 sec 0 sec
P2 50 sec 0 sec
CPU time slice = 10 sec
P1 & P2 States
Process Burst Time Start/Arrival Time
P1 30 sec 0 sec
P2 50 sec 0 sec
CPU time slice = 10 sec
Time Instant P1 P2
0 Running Ready
10 Ready Running
20 Running Ready
30 Ready Running
40 Running Ready
50 - Running
60 - Running
70 - Running
Process• AsState Modified
a process executes, it changes state
• New: The process is being created
• Ready: The process is waiting to be assigned to a
processor
• Running: Instructions are being executed
• Terminated: The process has finished execution
Process State Modified
• As a process executes, it changes state
• New: The process is being created
• Ready: The process is waiting to be assigned to a
processor
• Running: Instructions are being executed
• Waiting: The process is waiting for some event to
occur
• Terminated: The process has finished execution
Example
Process Burst Time Start/Arrival Time
P1 40 sec 0 sec
P2 40 sec 0 sec
CPU time slice = 10 sec
Time Instant P1 P2
0 Running Ready
10 Ready Running
20 Blocked for I/O Running
30 Running Ready
40 Running Blocked for I/O
50 Running Blocked for I/O
60 Exit Running
70 - Running
Exit
Class Exercise
Example
Process Burst Time Start/Arrival Time
P1 40 sec 0 sec
P2 40 sec 0 sec
CPU time slice = 10 sec
Time Instant P1 P2
0 Running Ready
10 Ready Running
20 Blocked for I/O Running
30 Running Ready
40 Running Blocked for I/O
50 Blocked for I/O Running
60 Running Blocked for I/O
70 Exit Running
Exit
To make sure… You have Understood !
Process Burst Time Start/Arrival Time
P1 30 sec 0 sec
P2 40 sec 0 sec
CPU time slice = 10 sec
Time Instant P1 P2
0 Running Ready
10 Ready Running
20 Blocked for I/O Running
30 Running Blocked for I/O
40 Running Blocked for I/O
50 Exit Blocked for I/O
60 - Running
70 - Running
Exit
Process Control Block (PCB)
Information associated with each
process
(also called task control block)
• Process state – running, waiting, etc.
• Program counter – location of
instruction to next execute
• CPU registers – contents of all
process-centric registers
• CPU scheduling information –
priorities, scheduling queue pointers
• Memory-management information –
memory allocated to the process
• Accounting information – CPU used,
clock time elapsed since start, time
limits
• I/O status information – I/O devices
allocated to process, list of open files
CPU Switch From Process to Process
Threads
• So far, process has a single thread of execution
• Consider having multiple program counters per
process
• Multiple locations can execute at once
• Multiple threads of control -> threads
• Must then have storage for thread details, multiple
program counters in PCB.
Process Scheduling
• Maximize CPU use, quickly switch processes
onto CPU for time sharing
• Process scheduler selects among available
processes for next execution on CPU
• Maintains scheduling queues of processes
• Job queue – set of all processes in the system
• Ready queue – set of all processes residing in main
memory, ready and waiting to execute
• Device queues – set of processes waiting for an I/O
device
• Processes migrate among the various queues
Ready Queue And Various I/O Device Queues
Representation of Process Scheduling