Ch-3 - OS Process Management
Ch-3 - OS Process Management
CS3500 – CHAP - 3
PROF. SUKHENDU DAS,
DEPTT. OF COMPUTER SCIENCE AND ENGG., IIT MADRAS, CHENNAI – 600036.
Email: sdas@cse.iitm.ac.in
URL: //www.cse.iitm.ac.in/~vplab/os.html
https://sites.google.com/smail.iitm.ac.in/3500-os/
Aug. – 2022.
PROCESS MANAGEMENT
Outline
Process Concept
Process Scheduling
Operations on Processes
Interprocess Communication
IPC in Shared-Memory Systems
IPC in Message-Passing Systems
Communication in Client-Server Systems
Remote Procedure Call
What is A PROCESS?
An operating system executes a variety of programs that run as a
process.
Process – a program in execution; process execution must
progress in sequential fashion. No parallel execution of
instructions of a single 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 Process In Memory
What is A PROCESS? (Cont.)
Program ≠ Process
Process state
Process number
Program counter
CPU registers
CPU scheduling information
Memory-management information
Accounting information
I/O status information
What is a Thread*?
So far, process has a single thread of execution
Process termination
Process Creation
Parent process create children processes, which, in turn create other processes,
forming a tree of processes
Generally, process identified and managed via a process identifier (pid)
Resource sharing options
Parent and children share all resources
Children share subset of parent’s resources
Parent and child share no resources
Execution options
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
Parent process calls wait()waiting for the child to terminate
A Tree of Processes in Linux
Process Termination
Process executes last statement and then asks the operating system to delete it using
the exit() system call.
Returns status data from child to parent (via wait())
Process’ resources are deallocated by operating system
Parent may terminate the execution of children processes using the abort() system
call. Some reasons for doing so:
Child has exceeded allocated resources
Task assigned to child is no longer required
The parent is exiting, and the operating systems does not allow a child to continue if
its parent terminates
If no parent waiting (did not invoke wait()) process is a zombie
If parent terminated without invoking wait(), process is an orphan
Interprocess Communication
Processes within a system
independent or cooperating
Cooperating process can affect or be affected by other
processes, including sharing data
Reasons for cooperating processes:
Information sharing
Computation speedup
Modularity
Convenience
Two variations:
unbounded-buffer places no practical limit on the size of the buffer:
Producer never waits
Consumer waits if there is no buffer to consume
bounded-buffer assumes that there is a fixed buffer size
Producer must wait if all buffers are full
Consumer waits if there is no buffer to consume
IPC- Shared Memory
An area of memory shared among the processes that
wish to communicate
item buffer[BUFFER_SIZE];
int in = 0;
int out = 0;
item next_consumed;
item next_produced;
while (true) {
while (true) { while (in == out)
; /* do nothing */
/* produce an item in next produced */ next_consumed = buffer[out];
out = (out + 1) % BUFFER_SIZE;
while (((in + 1) % BUFFER_SIZE) == out)
; /* do nothing */ /* consume the item in next consumed
buffer[in] = next_produced; */
in = (in + 1) % BUFFER_SIZE; }
}
What about Filling all the Buffers?
Suppose that we wanted to provide a solution to the consumer-producer
problem that fills all the buffers.
Ordinary pipes – cannot be accessed from outside the process that created it.
Typically, a parent process creates a pipe and uses it to communicate with a child process
that it created.
Producer writes to one end (the write-end of the pipe)
Consumer reads from the other end (the read-end of the pipe)
Named pipes – can be accessed without a parent-child
relationship. Communication is bidirectional
Communications in Client-Server Systems
Sockets
Remote Procedure Calls
Sockets
A socket is defined as an endpoint for communication
Concatenation of IP address and port – a number
included at start of message packet to differentiate
network services on a host
The socket 161.25.19.8:1625 refers to port 1625 on
host 161.25.19.8
Communication consists between a pair of sockets
All ports below 1024 are well known, used for
standard services
Special IP address 127.0.0.1 (loopback) to refer to
system on which process is running Socket Communication
Remote Procedure Calls
Remote procedure call (RPC) abstracts procedure calls between processes on
networked systems
Again uses ports for service differentiation
Stubs – client-side proxy for the actual procedure on the server
The client-side stub locates the server and marshalls the parameters
The server-side stub receives this message, unpacks the marshalled parameters, and
performs the procedure on the server
Data representation handled via External Data Representation (XDL) format to
account for different architectures
Big-endian and little-endian
Remote communication has more failure scenarios than local
Messages can be delivered exactly once rather than at most once
OS typically provides a rendezvous (or matchmaker) service to connect client and
server
Execution of RPC