Unit 2
Unit 2
Chapter 3: Processes
Process Concept
Process Scheduling
Operations on Processes
Interprocess Communication
Examples of IPC Systems
Communication in Client-Server Systems
Objectives
To introduce the notion of a process -- a program in
execution, which forms the basis of all computation
A process includes:
program counter
stack
data section
The Process
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
Program is passive entity, process is active
Program becomes process when executable file loaded into memory
Execution of program started via GUI mouse clicks, command line
entry of its name, etc
One program can be several processes
Consider multiple users executing the same program
Process in Memory
Process State
As a process executes, it changes state
new: The process is being created
running: Instructions are being executed
waiting: The process is waiting for some event to occur
ready: The process is waiting to be assigned to a processor
terminated: The process has finished execution
Diagram of Process State
Process Control Block (PCB)
Information associated with each process
Process state
Program counter
CPU registers
CPU scheduling information
Memory-management information
Accounting information
I/O status information
Process Control Block (PCB)
CPU Switch From Process to Process
Process Scheduling
Resource sharing
Parent and children share all resources
Children share subset of parents resources
Parent and child share no resources
Execution
Parent and children execute concurrently
Parent waits until children terminate
Process Creation (Cont.)
Address space
Child duplicate of parent
Child has a program loaded into it
UNIX examples
fork system call creates new process
exec system call used after a fork to replace the process memory space with
a new program
Process Creation
Process Termination
Process executes last statement and asks the operating system to
delete it (exit)
Output data from child to parent (via wait)
Process resources are deallocated by operating system
Software solutions
algorithms whos correctness does not rely on any other assumptions.
Hardware solutions
rely on some special machine instructions.
Operating System solutions
provide some functions and data structures to the programmer through
system/library calls.
Programming Language solutions
Linguistic constructs provided as part of a language
Dekker's algorithm
Dekker's algorithm is the first known correct solution to the mutual
exclusion problem in concurrent programming. The solution is attributed
to Dutch mathematician Th. J. Dekker by Edsger W. Dijkstra in his
manuscript on cooperating sequential processes.
It allows two threads to share a single-use resource without conflict, using
only shared memory for communication.
If two processes attempt to enter a critical section at the same time, the
algorithm will allow only one process in, based on whose turn it is.
If one process is already in the critical section, the other process will busy
wait for the first process to exit.
This is done by the use of two flags, flag[0] and flag[1], which indicate an
intention to enter the critical section and a turn variable that indicates who
has priority between the two processes.
Peterson's algorithm
Peterson's algorithm is a concurrent programming algorithm developed by
Gary L. Peterson in a 1981 paper. It is known as a simple algorithm when
compared to others. Peterson proved the algorithm using both the 2-
process case and the N-process case.
Peterson's algorithm is used for mutual exclusion and allows two processes
to share a single-use resource without conflict. It uses only shared memory
for communication. Peterson's formula originally worked only with two
processes, but has since been generalized for more than two.
Just as in Dekker's algorithm, turn variables (turn) and status flags (flag) are
conditions or variables that are used in Peterson's algorithm. Because of
these two conditions, and because of waiting for a turn only if other flags
are set, the need to clear and reset flags is avoided. After a flag is set, the
turn is immediately given away when using Peterson's algorithm.
Semaphore