Process Concept
Process Concept
Process Concepts
• The concept of a process.
• The process life cycle.
• Process states and state transitions.
• Process control blocks (PCBs)/process
descriptors.
• How interrupts enable hardware to
communicate with software.
• How processes converse with one another
via inter-process communication (IPC).
Process
• A process (sometimes called a task, or a job) is,
informally,
– A program in execution, it is an entity that
represents a program in execution
• “Process” is not the same as “program”
– A program is a static entity whereas a process is
dynamic since it represents the execution program.
– The program is not only part of a process; the
process also contains the execution state
• A process is an entity with its own address space.
The address space typically consists of
– text region: code
– data region: variables and dynamically allocated
memory
– stack region: instructions and local variables
Process States
A process state is de ned as the status of a process
(e.g., running, blocked, ready, etc.). A process moves
through a series of discrete process states.
• Running State: the process is executing on a
processor
• Ready State: the process could execute on a
processor when one is available
• Blocked State: the process is waiting for some
event to happen before it can proceed.
A Two-State Process Model
Process Transitions in
the Two-State Process Model
• When the OS creates a new process, it is initially placed
in the not-running state
– It’s waiting for an opportunity to execute
• At the end of each time slice, the CPU scheduler selects
a new process to run
– The previously running process is paused — moved from
the running state into the not-running state (at tail of
queue)
– The new process (at head of queue) is dispatched —
moved from the not running state into the running state
• If the running process completes its execution, it exits,
and the CPU scheduler is invoked again
• If it doesn’t complete, but its time is up, it gets moved into
the not-running state anyway, and the CPU scheduler
chooses a new process to execute
A Five-State Process Model
• The not-running state in the two-state
model has now been split into a ready
state and a blocked state
– Running — currently being executed
– Ready — prepared to execute
– Blocked — waiting for some event to occur
(for an I/O operation to complete, or a
resource to become available, etc.)
– New — just been created
– Exit — just been terminated
State transition diagram
State Transitions in Five-State
Process Model
• New → Ready
– Admitted to ready queue; can now be considered by
CPU scheduler
• Ready → Running
– CPU scheduler chooses that process to execute next,
according to some scheduling algorithm
• Running → Ready
– Process has used up its current time slice
• 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
Waiting on Something to
Happen…
• Some reasons why a process that might otherwise be
running needs to wait:
– Wait for user to type the next key
– Wait for output to appear on the screen
– Program tried to read a le — wait while
• OS decides which disk blocks to read, and then actually
reads the requested information into memory
– Netscape tries to follow a link (URL) — wait while OS
determines address, requests data, reads packets, displays
requested web page
• OS must distinguish between:
– Processes that are ready to run and are waiting their turn
for another time slice
– Processes that are waiting for something to happen (OS
operation, hardware event, etc.)
Process Control Block (PCB)
• Process Control Block is a data structure
containing information that characterizes a
process also called a process descriptor. The OS
typically performs several operations when it
creates a process, including assigning a process
identi cation number (PID) to the process and
creating a process control block (PCB), which
stores the program counter (i.e., the pointer to the
address next instruction the process will execute).
• When a process terminates (or is terminated by
the operating system), the operating system
removes the process from the process table and
frees all of the process's resources, including its
memory.
Process Control Block (PCB)
• For every process, the OS maintains a Process Control
Block (PCB), a data structure that represents the process
and its state:
– Process id number (PID)
– User-id of owner
– Memory space (static, dynamic)
– Program Counter, Stack Pointer, general purpose registers
– Process state (running, not-running, etc.)
– CPU scheduling information (e.g., priority)
– List of open les
– I/O states, I/O in progress
– Pointers into CPU scheduler’s state queues (e.g., the
waiting queue)
• A process table is used to allow PCB to be accessed
quickly.
Process Creation
• Processes are created and deleted
dynamically
• Process which creates another process is
called a parent process; the created
process is called a child process.
• Resources required when creating
process
• CPU time, les, memory, I/O devices etc.
Process Creation
• Resource sharing
– Parent and children share all resources.
– Children share subset of parent’s resources - prevents
many processes from overloading the system.
– Parent and children share no resources.
• Execution
– Parent and child execute concurrently.
– Parent waits until child has terminated.
• Address Space
– Child process is duplicate of parent process.
– Child process has a program loaded into it.
Process Termination
• Process executes last statement and asks
the operating system to delete it (
– Output data from child to parent (via wait).
exit).
– Process’ resources are deallocated by operating system.
• Parent may terminate execution of child
processes.
– Child has exceeded allocated resources.
– Task assigned to child is no longer required.
– Parent is exiting
» OS does not allow child to continue if parent
terminates
» Cascading termination
Process Creation/Termination
• Reasons for process creation
– User logs on
– User starts a program
– OS creates process to provide a service (e.g., printer
daemon to manage printer)
– Program starts another process (e.g., netscape calls xv to
display a picture)
• Reasons for process termination
– Normal completion
– Arithmetic error, or data misuse (e.g., wrong type)
– Invalid instruction execution
– Insu cient memory available, or memory bounds violation
– Resource protection error
– I/O failure
Cooperating Processes
• Processes can cooperate with each other to
accomplish a single task.
• Cooperating processes can:
– Improve performance by overlapping activities or
performing work in parallel
– Enable an application to achieve a better program
structure as a set of cooperating processes, where
each is smaller than a single monolithic program
– Easily share information
• Issues:
– How do the processes communicate?
– How do the processes share data?
Cooperating Processes
• Concurrent Processes can be
– Independent processes
» cannot a ect or be a ected by the execution of another
process.
– Cooperating processes
» can a ect or be a ected by the execution of another
process.
• Advantages of process cooperation:
» Information sharing
» Computation speedup
» Modularity
» Convenience(e.g. editing, printing, compiling)
• Concurrent execution requires
» process communication and process synchronization
Process Operations
• Create and destroy a process