Operating System must provide a mechanism for process creation and deletion
Process Creation
Parent process creates children processes, which, in turn create other processes, forming a tree of processes; in Unix use system call fork( ).
A process needs resources (CPU time, memory, files, I/O).
When a process creates a sub-process:
For resources following possibilities exist
Parent and children may share all resources.
Children may share subset of parent’s resources.
Parent and children may share no resources.
For execution following possibilities exist
Parent and children may execute concurrently.
Parent may wait until children terminate.
For address space following possibilities exist
Child process address space is duplicate of parent’s.
Child has a program loaded into it. -> in UNIX: use of execlp().
Process termination
A process terminates when it executes last statement and asks the OS to delete it ( exit ); at that point, the process may output data from child to parent (via wait ), and process’ resources are deallocated by the OS.
Parent may terminate execution of children processes (abort); Reasons for termination:
Child has exceeded allocated resources.
Task assigned to child is no longer required.
Parent is exiting, and OS does not allow child to continue if its parent terminates.
Cooperating Processes
The concurrent processes executing in OS may be either independent or cooperating processes.
Independent processes cannot affect or be affected by the execution of another process.
Cooperating processes can affect or be affected by the execution of another process.
Advantages of process cooperation:
Information sharing
several users may need the same piece of information.
Computation speed-up
break a task into subtasks and execute in parallel
Modularity
dividing the system function into separate processes.
Convenience
A user may want to do editing, printing in parallel.
Example of concurrent processes:
Producer-consumer problem
Paradigm for cooperating processes; producer process produces information that is consumed by a consumer process .
To allow producer and consumer processes to run concurrently, there is a buffer of items that can be filled by the producer, and emptied by the consumer.
Unbounded-buffer places no practical limit on the size of the buffer.
Bounded-buffer assumes that there is a fixed buffer size.
The buffer can be in a form of shared memory, or provided by the OS through the use of interprocess-communication (IPC).
Interprocess Communication (IPC)
Cooperating processes can communicate:
via a shared-memory environment .
via an interprocess-communication facility . (means provided by OS for processes to communicate; best provided by a message passing system.)
The function of a message system
processes communicate with each other without resorting to shared variables.
IPC
IPC facility provides at least 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.
IPC
Several methods for logically implementing a link and send / receive operations:
Direct or indirect communication.
Symmetric or asymmetric communication.
Automatic or explicit buffering.
Send by copy or send by reference.
Fixed-sized or variable-sized messages.
Direct communication
In direct-communication, each process must explicitly name the recipient or sender of the communication.
Primitives used:
Send (P, message) – send a message to process P.
Receive (Q, message) – receive a message from process Q.
Direct communication …..
Properties of communication link for this scheme:
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 bidirectional.
Indirect communication
Messages are sent to and received from mailboxes (also referred to as ports).
Each mailbox has a unique id.
Processes can communicate only if they share a mailbox.
Primitives used:
Send (A, message) – send a message to mailbox A.
Receive (A, message) – receive a message from mailbox A.
Indirect communication
Properties of communication link for this scheme:
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.
Operations:
Create a new mailbox.
Send and receive messages through mailbox.
Destroy a mailbox.
Indirect communication ….
Mailbox sharing If processes P1, P2, and P3 share a mailbox A, and process P1 sends a message to mailbox A while processes P2 and P3 execute a receive from A, which process will receive the message sent by P1?
Three possible 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 can be either blocking ( synchronous ) or nonblocking (asynchronous).
Blocking send: The sender is blocked until the message is received.
Nonblocking send: the sender resumes operation after sending the message.
Blocking receive: the receiver blocks until message is available.
Nonblocking receive: receiver retrieves either a valid message or a NULL.
Buffering
Whether the communication is direct or indirect, messages exchanged by communicating processes reside in a temporary queue. Such a queue can be implemented in three ways
zero capacity
bounded capacity
unbounded capacity
For the non-zero capacity case, the sender does not know if a message has arrived at the destination (may use asynchronous communication; the receiver sends back an acknowledgement to the sender.)
Exception conditions – error recovery
An Error may occur during process communications;
When a failure occurs, some error recovery must takes place.
Process terminates
E xample: process P is waiting for a message from a terminated process Q.
Solution: OS terminates P or notify P that Q has terminated.
Exception conditions – error recovery
Lost messages
Example: message from P to Q become lost due to hardware error;
Solution:
OS detects it and resend the message.
Sender detects it and resend.
OS detects it and let the sender know.
Scrambled messages
Example: message is received but in error; detected by parity checking, CRC.
Solution: resend it.
Communication in Client-Server Systems
Sockets
A socket is defined as an endpoint for communication .
Concatenation of IP address and port.
The socket 161.25.19.8:1625 refers to port 1625 on host 161.25.19.8
Communication consists between a pair of sockets.
Socket Communication
Remote Procedure Calls
Remote procedure call (RPC) abstracts procedure calls between processes on networked systems.
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.
Execution of RPC
Remote Method Invocation (RMI)
Remote Method Invocation is a Java mechanism similar to RPCs.
RMI allows a Java program on one machine to invoke a method on a remote object.
0 comments
Post a comment