Lecture 02
Lecture 02
System
Professor Mangal Sain
Lecture 2
Processes
OBJECTIVES
Operation on Processes
OPERATIONS ON PROCESSES
Execution options
Parent and children execute concurrently
Parent waits until children terminate
A TREE OF PROCESSES IN LINUX
init
pid = 1
emacs tcsch
ps
pid = 9204 pid = 4005
pid = 9298
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 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
PROCESS TERMINATION
Some operating systems do not allow child to exists if its
parent has terminated. If a process terminates, then all
its children must also be terminated.
cascading termination. All children, grandchildren, etc. are
terminated.
The termination is initiated by the operating system.
The parent process may wait for termination of a child
process by using the wait()system call. The call returns
status information and the pid of the terminated process
pid = wait(&status);
If no parent waiting (did not invoke wait()) process is a
zombie
If parent terminated without invoking wait , process is
an orphan
MULTIPROCESS ARCHITECTURE – CHROME BROWSER
Many web browsers ran as single process (some still do)
If one web site causes trouble, entire browser can hang or crash
Google Chrome Browser is multiprocess with 3 different types of
processes:
Browser process manages user interface, disk and network I/O
Renderer process renders web pages, deals with HTML, Javascript. A new
renderer created for each website opened
Runs in sandbox restricting disk and network I/O, minimizing effect of security exploits
Plug-in process for each type of plug-in
INTERPROCESS COMMUNICATION
Processes within a system may be 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
Cooperating processes need interprocess
communication (IPC)
Two models of IPC
Shared memory
Message passing
COMMUNICATIONS MODELS
Hardware bus
Network
Logical:
Direct or indirect
Synchronous or asynchronous
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.
INDIRECT COMMUNICATION
Operations
create a new mailbox (port)
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
Lecture 2 – Part 3
Operation on Processes
SYNCHRONIZATION
Message passing may be either blocking or non-blocking
Blocking is considered synchronous
Blocking send -- the sender is blocked until the message is
received
Blocking receive -- the receiver is blocked until a message is
available
Non-blocking is considered asynchronous
Non-blocking send -- the sender sends the message and
continue
Non-blocking receive -- the receiver receives:
A valid message, or
Null message
Different combinations possible
If both send and receive are blocking, we have a rendezvous
SYNCHRONIZATION (CONT.)
message next_consumed;
while (true) {
receive(next_consumed);
Sockets
Remote Procedure Calls
Pipes
Three types of
sockets
Connection-
oriented (TCP)
Connectionless
(UDP)
MulticastSocket
class– data can be
sent to multiple
recipients