Chapter 3: Process Concept: Al-Mansour University College Software Engineering and Information Technology Department
Chapter 3: Process Concept: Al-Mansour University College Software Engineering and Information Technology Department
Chapter 3: Process Concept: Al-Mansour University College Software Engineering and Information Technology Department
week 3
CHAPTER 3: PROCESS CONCEPT
3 Operations on Processes
4 Interprocess Communication
6 Communication in Client-Server
Systems
PROCESS CONCEPT
An operating system executes a variety of programs:
Batch system – jobs
Time-shared systems – user programs or tasks
Textbook uses the terms job and process almost interchangeably
Process – a program in execution; process execution must progress in sequential fashion
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
Program is passive entity stored on disk (executable file), process is active
Program becomes process when executable file loaded into memory
Execution of program started via GUI mouse clicks, command line entry of its name, etc
One program can be several processes
Consider multiple users executing the same program
PROCESS IN MEMORY
PROCESS STATE
As a process executes, it changes state
new: The process is being created
running: Instructions are being executed
waiting: The process is waiting for some event to occur
ready: The process is waiting to be assigned to a processor
terminated: The process has finished execution
DIAGRAM OF PROCESS STATE
PROCESS CONTROL BLOCK (PCB)
Information associated with each process
(also called task control block)
Process state – running, waiting, etc
Execution options
Parent and children execute concurrently
Parent waits until children terminate
A TREE OF PROCESSES IN LINUX
i ni t
pi d = 1
l o gi n kt hr e add s s hd
pi d = 8 415 pi d = 2 pi d = 302 8
e ma c s t cs ch
ps
pi d = 920 4 pi d = 4005
pi d = 9 298
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
C PROGRAM FORKING SEPARATE PROCESS
CREATING A SEPARATE PROCESS VIA WINDOWS
API
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
If parent is exiting
Some operating systems do not allow child to continue if its parent terminates
All children terminated - cascading termination
Shared data
#define BUFFER_SIZE 10
typedef struct {
. . .
} item;
item buffer[BUFFER_SIZE];
int in = 0;
int out = 0;
Solution is correct, but can only use BUFFER_SIZE-1
elements
BOUNDED-BUFFER – PRODUCER
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
port_allocate()
Send and receive are flexible, for example four options if mailbox full:
Wait indefinitely
Wait at most n milliseconds
Return immediately
Temporarily cache a message
EXAMPLES OF IPC SYSTEMS – WINDOWS
Sockets
Pipes
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
SOCKETS IN JAVA
Three types of sockets
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?
Can the pipes be used over a network?
ORDINARY PIPES
Ordinary Pipes allow communication in standard producer-consumer style
Consumer reads from the other end (the read-end of the pipe)
Communication is bidirectional