OS Chapter 3
OS Chapter 3
OS Chapter 3
Chapter 3
Dr. Sohail Abbas
Chapter 3: Processes
Multiple parts:
The program code, also called text
section. Also includes 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
Laboratory
Execution options
Parent and children execute concurrently
Parent waits until children terminate
UNIX examples
fork() system call creates new process
the return code for the fork() is zero for the new (child)
process, whereas the (nonzero) process identifier of the
child is returned to the parent.
exec() system call used after a fork() to replace the
process’ memory space with a new program
When the exec()is not called: the parent and child are
concurrent processes running the same code, each process
has its own copy of data.
Parent process can issue a wait() to move itself off the
ready queue until the termination of the child.
1. A process
2. Zombie process
3. Orphan process
The form of the data and the location are determined by these
processes and are not under the operating system’s control.
The processes are also responsible for ensuring that they are
not writing to the same location simultaneously.
item buffer[BUFFER_SIZE];
int in = 0;
int out = 0;
The buffer is empty when in == out;
And full when ((in + 1) % BUFFER SIZE) == out.
Solution is correct, but can only use BUFFER_SIZE-1 elements
item next_produced;
while (true) {
/* produce an item in next produced */
while (((in + 1) % BUFFER_SIZE) == out)
; /* do nothing */
buffer[in] = next_produced;
in = (in + 1) % BUFFER_SIZE;
}
Implementation issues:
How are links established?
Can a link be associated with more than two processes?
How many links can be there between every pair of
communicating processes?
Is a link unidirectional or bi-directional?
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.
Mailbox vs Shared Memory
Mailbox is like a pipe
In Mailbox, when a receiver reads a message, it is deleted.
Blocking Non-blocking
All ports below 1024 are well known, used for standard services
a telnet server listens to port 23; an FTP server listens to
port 21; and a web, or HTTP, server listens to port 80
Connection-oriented (TCP)
Connectionless (UDP)
MulticastSocket class– data can be sent to multiple
recipients
Issues
Is communication unidirectional or bidirectional?
In the case of two-way communication, is it half or full-
duplex?
Must there exist a relationship (i.e. parent-child) between
the communicating processes?
Consumer reads from the other end (the read-end of the pipe)
Communication is bidirectional
Pipes Sockets