“Only a brain-damaged operating system would support task switching and not make the simple next step of
supporting multitasking.”
– Calvin Keegan
Processes
• Abstraction of a running program
• Unit of work in the system
• Pseudoparallelism
• A process is traced by listing the sequence of instructions that execute for that process
• The process model
– Sequential Process/Task
∗ A program in execution
∗ Program code
∗ Current activity
∗ Process stack
· subroutine parameters
· return addresses
· temporary variables
∗ Data section
· Global variables
• Concurrent Processes
– Multiprogramming
– Interleaving of traces of different processes characterizes the behavior of the cpu
– Physical resource sharing
∗ Required due to limited hardware resources
– Logical resource sharing
∗ Concurrent access to the same resource like files
– Computation speedup
∗ Break each task into subtasks
∗ Execute each subtask on separate processing element
– Modularity
∗ Division of system functions into separate modules
– Convenience
∗ Perform a number of tasks in parallel
– Real-time requirements for I/O
• Process Hierarchies
– Parent-child relationship
– fork(2) call in Unix
– In ms-dos, parent suspends itself and lets the child execute
• Process states
,Interprocess Communication 13
– Running
– Ready (Not running, waiting for the CPU)
– Blocked / Wait on an event (other than cpu) (Not running)
– Two other states complete the five-state model – New and Exit
∗ A process being created can be said to be in state New; it will be in state Ready after it has been
created
∗ A process being terminated can be said to be in state Exit
Blocked
Event
I Event
@
occurs @ wait
@
Dispatch-
New - Ready Running - Exit
Timeout
– Above model suffices for most of the discussion on process management in operating systems; however,
it is limited in the sense that the system screeches to a halt (even in the model) if all the processes are
resident in memory and they all are waiting for some event to happen
– Create a new state Suspend to keep track of blocked processes that have been temporarily kicked out of
memory to make room for new processes to come in
– The state transition diagram in the revised model is
Suspended Suspend
Blocked
@ Event
I Event
@
Activate
@ occurs @ wait
R
@
@
Dispatch-
New - Ready Running - Exit
Timeout
– Which process to grant the CPU when the current process is swapped out?
∗ Preference for a previously suspended process over a new process to avoid increasing the total load
on the system
∗ Suspended processes are actually blocked at the time of suspension and making them ready will just
change their state back to blocked
∗ Decide whether the process is blocked on an event (suspended or not) or whether the process has
been swapped out (suspended or not)
– The new state transition diagram is
Blocked
Suspended
Event
I@
@
Suspend Activate
occurs @@
@
@
R
Ready
Blocked
Suspended
@ Event
I Event
@
Activate
@ occurs @ wait
R
@
@
Dispatch-
New - Ready Running - Exit
Timeout
, Interprocess Communication 14
Process control
• Modes of execution
– OS execution vs user process execution
– OS may prevent execution of some instructions in user mode and allow them to be executed only in
privileged mode (also called kernel mode, system mode, or control mode)
∗ Read/write a control register, such as psw
∗ Primitive I/O and memory management
– The two modes protect the OS data structures from interference by user code
– Kernel mode provides full control of the system that may not be needed for user programs
– The kernel mode can be entered by setting a bit in the psw
– The system can enter privileged mode as a result of a request from user code and returns to user mode
after completing the request
• Implementation of processes
– Process table
∗ One entry for each process
∗ program counter
∗ stack pointer
∗ memory allocation
∗ open files
∗ accounting and scheduling information
– Interrupt vector
∗ Contains address of interrupt service procedure
· saves all registers in the process table entry
· services the interrupt
• Process creation
– Assign a unique process identifier to the new process; add this process to the system process table that
contains one entry for each process
– Allocate space for all elements of process image – space for code, data, and user stack; values can be set
by default or based on parameters entered at job creation time
– Allocation of resources (CPU time, memory, files) – use either of the following policies
∗ New process obtains resources directly from the OS
∗ New process constrained to share resources from a subset of the parent process
– Build the data structures that are needed to manage the process, especially process control block
– When is a process created? – job submission, login, application such as printing
– Static or dynamic process creation
– Initialization data (input)
– Process execution
∗ Parent continues to execute concurrently with its children
∗ Parent waits until all its children have terminated
• Process switching
– Interrupt a running process and assign control to a different process
– Difference between process switching and mode switching