0% found this document useful (0 votes)
4 views30 pages

Chap3 Process Extended

The document discusses various aspects of process scheduling, creation, and communication in operating systems. It explains the roles of short-term and long-term schedulers, the structure of process trees, and interprocess communication models such as shared memory and message passing. Additionally, it covers synchronization methods and examples of IPC mechanisms like pipes, sockets, and remote procedure calls.

Uploaded by

akshayacrao1105
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views30 pages

Chap3 Process Extended

The document discusses various aspects of process scheduling, creation, and communication in operating systems. It explains the roles of short-term and long-term schedulers, the structure of process trees, and interprocess communication models such as shared memory and message passing. Additionally, it covers synchronization methods and examples of IPC mechanisms like pipes, sockets, and remote procedure calls.

Uploaded by

akshayacrao1105
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Schedulers (Cont.

)
◼ Short-term scheduler is invoked very frequently
(milliseconds)  (must be fast)
◼ Long-term scheduler is invoked very infrequently
(seconds, minutes)  (may be slow)
◼ The long-term scheduler controls the degree of
multiprogramming
◼ Processes can be described as either:
◼ I/O-bound process – spends more time doing

I/O than computations, many short CPU bursts


◼ CPU-bound process – spends more time doing

computations; few very long CPU bursts


Process Creation
◼ Parent process create children processes, which, in
turn create other processes, forming a tree of
processes
◼ Resource sharing
◼ Parent and children share all resources

◼ Children share subset of parent’s 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
A Tree of Processes on Solaris
Process Creation
C Program Forking Separate
Process
#include<stdio.h>
main()
{
int pid;
/* fork another process */
pid = fork();
if (pid < 0) { /* error occurred */
printf("Fork Failed");

}
else if (pid == 0) { /* child process */
printf(“%d”, getpid());
printf(“%d”, getppid());
}
else { /* parent process */
/* parent will wait for the child to complete */
wait (NULL);
printf ("Child Complete");
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
◼ Parent may terminate execution of children processes
(abort)
◼ Child has exceeded allocated resources

◼ Task assigned to child is no longer required


Contd..
◼ If parent is exiting
◼ Some operating system do not allow child to

continue if its parent terminates


◼ All children terminated - cascading

termination
Cooperating Processes
◼ Independent process cannot affect or be affected
by the execution of another process
◼ Cooperating process can affect or be affected by
the execution of another process
◼ Advantages of process cooperation
◼ Information sharing

◼ Computation speed-up

◼ Modularity

◼ Convenience
Inter process communication models
Inter process communication models

◼ Shared Memory – Maximum speed,


faster, System calls are used to
established shared memory regions, no
assistance from kernel
Eg: multiprocessor systems
◼ Message Passing – smaller amount of

data, easier to implement, system calls


are used that take more of kernel help
Eg: Distributed systems
Implementation of communication link

◼ Physical:
◼ Shared memory
◼ Hardware bus
◼ Network
◼ Logical:
◼ Direct or indirect
◼ Synchronous or asynchronous
◼ Automatic or explicit buffering
Interprocess Communication
(IPC)
◼ Mechanism for processes to communicate and to
synchronize their actions
◼ Message system – processes communicate with each
other without resorting to shared variables
◼ IPC facility provides two operations:
◼ send(message) – message size fixed or variable

◼ receive(message)

◼ If P and Q wish to communicate, they need to:


◼ establish a communication link between them

◼ exchange messages via send/receive

◼ Implementation of communication link


◼ physical (e.g., shared memory, hardware bus)

◼ logical (e.g., logical properties)


Direct Communication
◼ Processes must name each other explicitly:
◼ send (P, message) – send a message to process

P
◼ receive(Q, message) – receive a message from

process Q
◼ Properties of communication link
◼ Links are established automatically

◼ A link is associated with exactly one pair of

communicating processes
◼ Between each pair there exists exactly one link

◼ The link may be unidirectional, but is usually bi-

directional
Indirect Communication
◼ Messages are directed and received from
mailboxes (also referred to as ports)
◼ Each mailbox has a unique id

◼ Processes can communicate only if they share a

mailbox
◼ Properties of communication link
◼ Link established only if processes share a

common mailbox
◼ A link may be associated with many processes

◼ Each pair of processes may share several

communication links
◼ Link may be unidirectional or bi-directional
Indirect Communication
◼ Operations
◼ create a new mailbox

◼ send and receive messages through mailbox

◼ destroy a mailbox

◼ Primitives are defined as:


send(A, message) – send a message to mailbox
A
receive(A, message) – receive a message from
mailbox A
Indirect Communication
◼ Mailbox sharing
◼ P1, P2, and P3 share mailbox A

◼ P1, sends; P2 and P3 receive

◼ Who gets the message?

◼ Solutions
◼ Allow a link to be associated with at most two

processes
◼ Allow only one process at a time to execute a

receive operation
◼ Allow the system to select arbitrarily the receiver.

Sender is notified who the receiver was.


Synchronization
◼ Message passing may be either blocking or non-
blocking
◼ Blocking is considered synchronous
◼ Blocking send has the sender block until the

message is received
◼ Blocking receive has the receiver block until a

message is available
◼ Non-blocking is considered asynchronous
◼ Non-blocking send has the sender send the

message and continue


◼ Non-blocking receive has the receiver receive a

valid message or null


IPC Examples
Single Processor systems
◼ Shared memory – Pipes, named pipes

Multiple Processor systems


◼ Message passing – Mail Boxes

◼ Shared memory – Pipes, named pipes

◼ Client-Server : RPC, Socket

programming, RMI
POSIX Shared Memory
Creating a shared memory segment

Attaching the shared memory segment with a name

Writing some content into the shared memory segment

Detaching the shared memory


Pipes
◼ Acts as a conduit allowing two processes to communicate
◼ Features
◼ communication unidirectional
◼ Must there exist a relationship (i.e., parent-child) between the
communicating processes
◼ 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.
◼ Named pipes – can be accessed without a parent-child
relationship.
Example : Pipes
Communications in Client-Server Systems

◼ Sockets
◼ Remote Procedure Calls
◼ Remote Method Invocation (Java)
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 [Link]:1625 refers to port 1625 on
host [Link]
◼ Communication consists between a pair of sockets
◼ All ports below 1024 are well known, used for standard
services
◼ Special IP address [Link] (loopback) to refer to
system on which process is running
Remote Procedure Call
◼ 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
◼ On Windows, stub code compile from specification written in
Microsoft Interface Definition Language (MIDL)
RMI (Remote Method Invocation)
◼ Similar to RPC
◼ Used in JAVA environment
◼ Uses rmi package
◼ rmiregistry - to give bind, discovery and
lookup services
◼ Uses server containing remote objects
and their methods
Summary – Fill sub topics
◼ Process Concept

◼ Process Scheduling

◼ Operations on Processes

◼ Cooperating Processes

◼ Interprocess Communication
Tutorial Questions to answer
1. Differentiate between multi programming and multi-tasking
Operating systems
2. What are the parts of a process? What is a PCB?
3. What is the role of a medium term scheduler?
4. Name the IPC paradigms used in Operating systems
5. i) A process stack does not contain
a) Function parameters
b) Local variables
c) Return addresses
d) PID of child process
ii) The address of the next instruction to be executed by the current process
is provided by the
a) CPU registers
b) Program counter
c) Process stack
d) Pipe

You might also like