3.1 Process Concept
Early operating systems allowed only one program to be executed at a time. This
program had complete control of the system.
Current-day OS allow multiple programs to be loaded and executed concurrently
with the CPU(CPUs) multiplexed among them.
Textbook uses the terms joband processalmost interchangeably
Process –is a program in execution; it is more than program code (called text
section).
A process includes the current activity represented by the value of:
program counter
Processor’s registers
Stack, which contains temporary data( such as function parameters, return
addresses and local variables)
data section which contains global variables
Heap which is memory that is dynamically allocated during process run time.
A program by itself is not a process; it is a passive entity such as a file containing
a list of instructions stored on disk (often called executable file), whereas a
process is an active entity. A program becomes a process when an executable file
is loaded into memory either by double-clicking the program’s icon or entering the
name of the executable file on the CLI.
3.1 Process Concept…..
Although two processes may be associated with the same program, they are
nevertheless considered two separate execution sequences. Although the text
sections are equivalent, the data, heap, and stack sections vary. Example: a user
may invoke many copies of a web-browser program.
The diagram below shows a process in memory
3.2 Process State
The state of a process is defined in part by the current activity of that process. 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(such as an I/O completion or
reception of a signal)
ready: The process is waiting to be assigned to a processor
terminated: The process has finished execution
Note: only one process can berunning on any processor at any instant. Many processes
may be readyand waitinghowever.
3.3 Process Control Block (PCB)
Each process is represented in the OS by PCB also called task control block.
Information associated with each process are:
Process state: new, ready, running, waiting, halted…
Program counter(PC): indicates the address of the next instruction to be
executed for this process.
CPU registers: along with PC, this state information must be saved when an
interrupt occurs to allow the process be continued correctly afterward.
CPU scheduling information: includes process priority, pointers to scheduling
queues and other scheduling parameters.
Memory-management information: includes the value of base and limit
registers, page tables/segment tables and so on.
Accounting information: includes amount of CPU and real time used, time
limits, account numbers, process numbers etc.
I/O status information: includes the list of I/O devices allocated to the process, a
list of open files and so on.
CPU Switch From Process to Process
3.4 Process Scheduling
The objective of multiprogramming is to have some processes running at all times, to
maximize CPU utilization. The objective of time sharing is to switch the CPU among
processes so frequently that users can interact with each program while it is running.
Scheduling Queues
Job queue–set of all processes in the system
Ready queue–list of all processes residing in main memory, ready and waiting
to execute
Device queues–list of processes waiting for an I/O device
Processes migrate among the various queues
Ready Queue And Various I/O Device Queues
Representation of Process Scheduling
3.5 Schedulers
Long-term scheduler(or job scheduler) –selects which processes should be
brought into the memory(ready queue).
Short-term scheduler(or CPU scheduler) –selects from among the processes
that are ready to execute and allocates CPU to one of them
Difference between these two schedulers lies in frequency of execution
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 (the number of
processes in memory)
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
Addition of Medium Term Scheduling
Context Switch
Interrupts cause the OS to change a CPU from its current task and
to run a kernel routine. The system must save the state of the
process currently running and load the saved state (state restore)
for the new process.
Context-switch time is overhead because the system does no
useful work while switching
Context-switch times are dependent on hardware support.
Example: the set of registers in the system.
3.6 Operations on Processes
3.6.1 Process Creation
Parent process create children processes, which, in turn create other processes,
forming a tree of processes
To accomplish its tasks, a process will need certain resources which it will obtain
directly from OS or parent process.
Resource sharing
Parent and children share all resources
Children share subset of parent’s resources
Parent and child share no resources
Restricting a child process to a subset of the parent’s resources prevents any
process from overloading the system by creating too many sub processes.
Two possibilities in terms of execution
Parent and children execute concurrently
Parent waits until children terminate
Two possibilities in terms of address space
Child duplicate of parent(it has the same program and data as the parent)
Child has a program loaded into it
Process Creation (Cont.)
UNIX examples
forksystem call creates new process
execsystem call used after a forkto replace the process’ memory
space with a new program
A tree of processes on a typical Solaris
3.6.2 Process Termination
A process terminates when it finishes its last statement and asks
the operating system to delete it (by using the exit() system call).
The process may return a status value to its parent process
(via wait() system call).
Process’ resources are deallocated by operating system
Parent may terminate execution of its children processes using
appropriate system call (abort) for various reasons such as :
Child has exceeded allocated resources
Task assigned to child is no longer required
If parent is exiting
Some operating system do not allow child to continue if its
parent terminates
–All children terminated -cascading termination
3.7 Cooperating Processes
Independentprocess cannot affect or be affected by the execution of another
process(does not share data with any other process).
Cooperatingprocess can affect or be affected by the execution of another
process(shares data with other process)
Advantages of process cooperation
Information sharing: several users may need same information
Computation speed-up: enables parallel execution
Modularity
Convenience
Cooperating processes require an inter process communication (IPC)
mechanism to exchange data and information. Two models of IPC are
Shared memory
Message passing
3.7.1 Shared Memory
Processes can exchange information by reading and writing data to a
shared memory region established by the cooperating processes.
A shared memory region resides in the address space of the process
creating it. The other processes that wish to communicate attach it to their
address space.
Allows maximum speed and convenience of communication as it can be
done at memory speeds when within a computer.
System calls are required only to establish shared memory regions and no
assistance from the kernel is required to access the shared memory.
Producer-consumer problem: paradigm for cooperating processes,
producerprocess produces information that is consumed by a consumer
process. One solution is to use buffer
unbounded-bufferplaces no practical limit on the size of the buffer
bounded-bufferassumes that there is a fixed buffer size
Communications Models
Fig. IPC a) message passing b) shared-memory
3.7.2 Message Passing
Communication takes place by means of messages exchanged between the
cooperating processes. Example : a chat program used on WWW
Useful for exchanging smaller amount of data
Easier to implement than shared-memory for inter computer communication
Typically implemented using system calls and thus require more time-consuming
task of OS intervention.
Message-passing facility provides two operations:
send(message) –message size can be either fixed or variable
receive(message)
If Pand Qwish to communicate, they need to:
establish a communicationlinkbetween them
exchange messages via send/receive
Implementation of logical communication link
physical (e.g., shared memory, hardware bus)
logical (e.g., logical properties)
Implementation Questions
How are links established?
Can a link be associated with more than two processes?
How many links can there be between every pair of communicating
processes?
What is the capacity of a link?
Is the size of a message that the link can accommodate fixed or
variable?
Is a link unidirectional or bi-directional?
3.7.2.1 Direct Communication
Processes must name each other explicitly: the send() and
receive() primitives are defined as
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
3.7.2.2 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 are defined as
send(A, message) –send a message to mailbox A
receive(A, message) –receive a message from mailbox A
Properties of communication link
Link established only if processes share a common mailbox
A link may be associated with more than two processes
Each pair of processes may share several communication links
Link may be unidirectional or bi-directional
3.7.2.2 Indirect Communication……..
Mailbox sharing
Suppose processes P
1, P
2,andP
3share mailbox A and P
1, sends message to
A. which process will receive the message?
Solutions depends on
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 one receiver, not both. Sender is notified
who the receiver was.
A mailbox may be owned by a process or by OS
OS must provide operations to
create a new mailbox
send and receive messages through mailbox
destroy a mailbox
When a process that owns a mailbox terminates, the mailbox disappears. A
mailbox owned by OS has an existence of its own.
3.7.2.3 Synchronization
Message passing may be either blocking or non-blocking
Blockingis considered synchronous
Blocking send has the sender block until the message is
received by process or mailbox.
Blocking receive has the receiver block until a message is
available
Non-blockingis considered asynchronous
Non-blocking sendhas the sender send the message and
continue
Non-blocking receivehas the receiver receive a valid
message or null
3.7.2.4 Buffering
Queue of messages attached to the link to temporarily store
messages; implemented in one of three ways
1.Zero capacity –queue has zero length thus the link cannot
have any messages waiting in it. Sender must wait for receiver.
2.Bounded capacity –queue has finite length of nmessages.
Sender must wait if link full
3.Unbounded capacity –potentially infinite length queue. Sender
never waits.
Client-Server Communication
Sockets
Remote Procedure Calls
Remote Method Invocation (Java)
Sockets
A socket is defined as an endpoint for communication
Concatenation of IP address and port
The socket 161.25.19.8:1625refers to port 1625on 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 marshallsthe
parameters.
The server-side stub receives this message, unpacks the
marshalled parameters, and peforms the procedure on the server.
Execution of RPC
Remote Method Invocation
Remote Method Invocation (RMI) is a Java mechanism similar to
RPCs.
RMI allows a Java program on one machine to invoke a method on
a remote object.