0% found this document useful (0 votes)
34 views20 pages

Processes

Processes are instances of executing programs that have their own address space and resources. A process is created through process creation and can create child processes, forming a process hierarchy. Processes transition between states like running, ready, blocked, and terminated. The operating system maintains process information and controls scheduling through a process table containing process control blocks. Increasing the degree of multiprogramming through more available memory improves CPU utilization.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views20 pages

Processes

Processes are instances of executing programs that have their own address space and resources. A process is created through process creation and can create child processes, forming a process hierarchy. Processes transition between states like running, ready, blocked, and terminated. The operating system maintains process information and controls scheduling through a process table containing process control blocks. Increasing the degree of multiprogramming through more available memory improves CPU utilization.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Processes & Threads

Processes
Review
• Terminology
– Kernel mode, User mode
– Latency time
• Switch user mode  kernel mode
• Switch CPU a process to other process together
• System Calls
Review
• Process:
– A program in execution
– A program loaded into memory and executing
– Associated with each process is set of resources such as
executable code, data, stack, CPU registers value, PC, and
other information needing to run a program
– Associated with each process is its address space (i.e., all
memory locations that the process can read and write)
• Process table (array or linked list) stores all the
information of processes
• A process hierarchy (tree)

Tanenbaum, Fig. 1-13.


Objectives
• Processes
– Definition
– The process model
– Process creation
– Process hierarchies
– Process Termination
– Process States
– Transition States
– Implementation of Processes
– Degree of multiprogramming
Processes
Definition
• OS abstraction to support the ability to have (pseudo)
concurrent operation even when there is only one CPU
available
− An OS consists of a collection of processes: By switching the
CPU between processes, the OS can make the computer more
productive
• An instance of an executing program, including the
current values of PC, registers, and variables
− A process is not a program on the disk (this is just a file).
• Compare with a cake recipe (program) and the activity involving reading
the recipe, fetching ingredients, and baking the cake! (process)
• A process is a sequential stream of execution in its own
address space
Processes
The process model
• Early computers allowed only one program to be
executed at a time. (quantum or time slice)
• The program is a static (inactive) entity, whereas the
process is an active one
• A process is an activity of some kind
• A process has a program, input, output, and a state
• There are two parts of a process
– sequential execution: no concurrency inside a process;
everything happens sequentially (There is only one CPU and
one physical program counter)
– process state: everything that process interacts with (registers,
memory, files, etc)
Example

Tanenbaum, Fig. 2-1.


Processes
The process model (cont)
• Single-processor systems
– Pseudo-parallelism
• Multiprogramming
– Switching among processes (The CPU switches back and forth
from process to process)
• A single processor may be shared among several processes
– Scheduling algorithm
• Context switch
– Switching the CPU to another process requires saving the state
of the old process and loading the save state for the new process
– Context switch time is pure overhead because the system does not
useful work while switching. It‘s varies depending on the
hardware machine
– Has become a performance bottle neck
Processes
Process Creation
• In a general-purpose OS, the principal events that may cause
process creation are:
– System initialization
– Execution of a process creation system call by a running process
– A user request to create a new process
– Initiation of a batch job
• Automatically by the system
– At system initialization
– Foreground (application) and background (services) processes
• By another process
– A system call for process creation
– Situations
• A process needs help doing some computation
• A user action – interaction with the shell
• In general, a process (parent process) may create new processes
(children) via a create-process system call:
– fork() and execve() in UNIX
– CreateProcess in Win32
Processes
Process Hierarchies
• Process hierarchy
– Parent–Child Relationship
– The child can itself create new processes
– Tree of processes
• In UNIX OS
– A process creates another process, the parent process and child
process continue to be associated in certain ways
– A process and all of its children and further descendants
together form a process group
• In Windows OS
– All processes are equal (has no concept of process hierarchy)
– The parent is given a special token (called a handle) that it can
use to control the child
Processes
Process Termination
• After a process has been created, it may terminate
usually due to one of the following:
– Normal exit (task accomplished) (voluntary)
– Error exit (voluntary)
• Ex: inexistent files, insufficient or incorrect input
– Fatal error (involuntary)
• Ex: illegal instructions, division by zero etc.
– Killed by another process (involuntary)
• kill system call in Unix, or TerminateProcess in Win32.(in
some systems, if the parent terminates)
• Voluntary – using a special system call
• Involuntary – receiving an interruption
Processes
Process States
• Running
– Using the CPU at that instant (executed by the CPU) (or
Instructions are being executed)
• Ready
– Runnable; temporarily stopped to let another process run; but
the CPU available (or The process is waiting to be assigned to a
process)
• Blocked
– Unable to run until some external event happens (or The
process is waiting for some event to occur)
• New (optional)
– Waiting for same resources to be allocated (or The process is
being created)
• Terminated (optional)
– Keeping same information about the exit state (or The process
has finished execution)
Processes
Transition States
• New to Ready or Running
• Ready to Running (dispatch)
– its turn comes again
New Terminated
– selected by the scheduler (optional) (optional)

• Running to Ready (interrupt)


– suspended by the scheduler Running
– time slice expired
• Running to Blocked (block) Blocked Ready
– wait for some event to occur
• Blocked to Ready (ready)
– the awaited event occurs
• Running to Terminated (exit)
Processes
Implementation of Processes
• OS maintains a process table
– each process is allocate an entry – PCB (Process Control Block)
(Where process is located)
– used as a repository when the process is suspended or blocked
• A PCB contains all the information, that needed (varies
from system to system) so that a process can be restarted
as if it had never been stopped, such as
– Process ID
– process state (new, ready, running …)
– the value of the CPU registers (PC, Stack Pointer, other register)
– CPU scheduling information (process priority etc.)
– memory management information (pointers etc.)
– accounting information (the amount of CPU and real time used, time limits
etc.)
– I/O status information (outstanding I/O req., I/O devices allocated, list of
open files etc.)
– Process parent Id, process group ...
Processes
Implementation of Processes (cont)
• A PCB block
Processes
Implementation of Processes (cont)
• Example
Processes
Implementation of Processes (cont)
• Interrupt handling and scheduling are summarized

Tanenbaum, Fig. 2-5.


Processes
Degree of multiprogramming
• Shows the CPU utilization
CPU utilization = 1 - pn
– p: time waiting for I/O to complete
– n: number of processes
• Example
– A computer has 512MB of memory, with OS taking
128 MB and each user program also taking up 128MB
with an 80% average I/O wait
• CPU utilization = 1 – 80%((512-128)/128) = 49%
– Adding another 512MB,
• CPU utilization = 1 – 80%((1024-128)/128) = 79%
Summary
• Processes

Q&A
Next Lecture
• Threads

You might also like