You are on page 1of 5

Process ➢Program counter – The counter indicates

➢A process is more than the program code, the address of the next instruction to be
it includes executed for this process.
- The program code, also called text section ➢CPU registers – The registers vary in
- Current activity including program counter, number and type, depending on the
processor registers computer architecture. They include
- Stack containing temporary data accumulators, index registers, stack pointer,
Function parameters, return addresses, local and general-purpose registers, plus any
variables condition-code information. Along with the
- Data section containing global variables program counter, this state information
-Heap containing memory dynamically must be saved when an interrupt occurs, to
allocated during run time allow the process to be continued correctly
➢program is a passive entity(executable afterward
files), whereas a process is an active entity
➢A program becomes a process when an
executable file is loaded into memory.
Process State
➢As a process executes, it changes state.
➢The state of a process is defined in part by
the current activity of that process.
➢Each process may be in one of the
following states: ➢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 ➢Only one process can
be running on any processor at any instant.
Many processes may be ready and waiting.

➢CPU scheduling information- includes a


process priority, pointers to scheduling
queues, and any other scheduling
parameters.➢Memory-management
Process Control Block information -include such information as the
➢Each process is represented on the OS by value of the base and limit registers, the
a Process Control Block(PCB) also called a page tables, or the segment tables,
task control block. ➢It includes depending on the memory system used by
➢Process state – The state may be new, the operating system. ➢Accounting
ready running, waiting, halted etc information –includes the amount of CPU
and real time used, time limits, account
numbers, job or process numbers, and soon
Threads ➢The process could create a new
➢Process is a program that performs single subprocess and wait for the subprocess's
thread of execution. ➢Single thread of termination.➢The process could be
control allows the process to perform only removed forcibly from the CPU, as a result
one task at one time. ➢Modern Operating of an interrupt, and be put back in the ready
Systems have extended the process concept queue
to allow a process to have multiple threads Schedulers
of execution and thus to perform more than ➢A process migrates among the various
one task at a time. scheduling queues throughout its lifetime.
PROCESS SCHEDULING ➢The operating system must select, for
➢The objective of time sharing is to switch scheduling purposes, processes from these
the CPU among processes so frequently that queues in some fashion. ➢The selection
users can interact with each program while process is carried out by the appropriate
it is running. ➢The process scheduler scheduler ➢The long-term scheduler, or job
selects an available process for program scheduler, selects processes from pool and
execution on the CPU. ➢Maintains loads them into memory for execution.
scheduling queues of processes Long-term scheduler is invoked infrequently
*Job queue – set of all processes in the (seconds, minutes). ➢The short-term
system *Ready queue – set of all processes scheduler, or CPU scheduler, selects from
residing in main memory, ready and waiting among the processes that are ready to
to execute *Device queues – set of execute and allocates the CPU to one of
processes waiting for an I/O device them. Short-term scheduler is invoked
*Processes migrate among the various frequently (milliseconds) ⇒ (must be fast)
queues ➢Processes can be described as either:
➢A new process is initially put in the ready ➢I/O-bound process – spends more time
queue. It waits there until it is selected for doing I/O than computations, many short
execution, or is dispatched. Once the CPU bursts ➢CPU-bound process – spends
process is allocated the CPU and is more time doing computations; few very
executing, one of several events could long CPU bursts ➢Long-term scheduler
occur: ➢The process could issue an I/0 strives for good process mix of I/O-bound
request and then be placed in an I/0 queue. and CPU-bound processes.
Process Creation
➢A process may create several new
processes, via a create-process system
call,during the course of execution.
➢The creating process is called a parent
process, and the new processes are called
the children of that process. Each of these
new processes may in turn create other
processes, forming a tree of processes.
➢Generally, process identified and
managed via a process identifier (pid)
➢Resource sharing options ➢Parent and
children share all resources ➢Children share
subset of parent’s resources
➢Parent and child share no resources call. The call returns status information and
*Execution options the pid of the terminated process
➢Parent and children execute concurrently Shared-Memory Systems
➢Parent waits until children terminate ➢Interprocess communication using shared
*Possibilities in terms of the address space memory requires communicating processes
of the new process to establish a region of shared memory.
➢The child process is a duplicate of the ➢A shared-memory region resides in the
parent process ➢The child process has a address space of the process creating the
new program loaded into it. shared memory segment. Other processes
*UNIX examples that wish to communicate using this shared
➢fork() system call creates new process memory segment must attach it to their
➢exec() system call used after a fork() to address space.➢They can then exchange
replace the process’ memory space with a information by reading and writing data in
new program the shared areas. ➢The communication is
Process Termination under the control of the users processes not
➢Process executes last statement and then the OS➢Example for cooperating
asks the operating system to delete it using processes.:-Producer-consumer problem.
*A producer process produces information
the exit() system call ➢Returns status data
that is consumed by a consumer process.
from child to parent (via wait())➢Process’
*One solution to the producer-consumer
resources are deal located by operating
problem uses shared memory. *A buffer
system ➢A process can cause the which reside in a region of memory that is
termination of another process via an shared by the producer and consumer
appropriate system call. Such a system call processes is used *The producer and
can be invoked only by the parent of the consumer must be synchronized, so that the
process that is to be terminated ➢A parent consumer does not try to consume an item
needs to know the identities of its children. that has not yet been produced Two types
Thus, when one process creates a new of buffers can be used. *unbounded-buffer
process, the identity of the newly created places no practical limit on the size of the
process is passed to the parent. ➢A parent buffer *bounded-buffer assumes that there
may terminate the execution of one of its is a fixed buffer size
children for a variety of reasons, such as *Bounded capacity. The queue has finite
these: ➢Child has exceeded allocated length n; thus, at most n messages can
resources ➢Task assigned to child is no reside in it. If the queue is not full when a
longer required ➢The parent is exiting and new message is sent, the message is placed
the operating systems does not allow a child in the queue, and the sender can continue
to continue if its parent terminates ➢Some execution without waiting. The link's
operating systems do not allow child to exist capacity is finite. If the link is full, the sender
if its parent has terminated. If a process must block until space is available in the
terminates, then all its children must also be queue.
terminated. This phenomenon, referred to *Unbounded capacity. The queue's length is
as cascading termination. The termination is potentially infinite; thus, any number of
initiated by the operating system ➢The messages can wait in it. The sender never
parent process may wait for termination of blocks.
a child process by using the wait()system
➢Bounded-Buffer *Synchronous or asynchronous
➢Shared data communication. *Automatic or explicit
#define BUFFER_SIZE 10 buffering
typedef struct { Naming
... ➢Processes that want to communicate
} item; must have a way to refer to each other.
item buffer[BUFFER_SIZE]; They can use either direct or indirect
int in = 0; communication. Under direct
int out = 0; communication, each process that wants to
➢ The shared buffer is implemented as a communicate must explicitly name the
circular array with two logical pointers: in recipient or sender of the communication. In
and out. ➢ The variable in points to the this scheme, the send() and receive()
next free position in the buffer; out points primitives are defined as: *send(P, message)
to the first full position in the buffer. -Send a message to process P. *receive (Q,
message)-Receive a message from processQ
➢ The buffer is empty when in== out; the
*Symmetry in addressing- both the sender
buffer is full when ((in+ 1)% BUFFER_SIZE)
process and the receiver process must name
== out. ➢ Producer
the other to communicate.
item next_produced;
*Asymmetry in addressing- Here, only the
while (true) {
sender names the recipient; the recipient is
/* produce an item in next produced */
not required to name the sender.
while (((in + 1) % BUFFER_SIZE) == out)
*send (P, message) -Send a message to
; /* do nothing */
process P. *receive (id, message) -Receive a
buffer[in] = next_produced;
message from any process
in = (in + 1) % BUFFER_SIZE
Synchronization
➢Consumer
➢Message passing may be either blocking
item next_consumed;
or nonblockingalso known as synchronous
while(true){
and asynchronous. *Blocking send. The
while (in == out)
sending process is blocked until the message
;/*donothing*/
is received by the receiving process or by
next_consumed = buffer[out];
the mailbox.*Nonblocking send. The sending
out = (out + 1) % BUFFER_SIZE;
process sends the message and resumes
/* consume the item in next consumed */ }
operation. *Blocking receive. The receiver
Message-Passing Systems blocks until a message is available.
➢Message passing provides a mechanism to *Nonblocking receive. The receiver retrieves
allow processes to communicate and to either a valid message or a null. Buffering
synchronize their actions without sharing ➢Whether communication is direct or
the same address space. ➢A message- indirect, messages exchanged by
passing facility provides at least two communicating processes reside in a
operations: send (message) and receive temporary queue. Basically, such queues
(message). ➢If processes P and Q want to can be implemented in three ways:
communicate, they must send messages to *Zero capacity -The queue has a maximum
and receive messages from each other; a length of zero; thus, the link cannot have
communication link must exist between any messages waiting in it. In this case, the
them. ➢methods for logically implementing sender must block until the recipient
a link and the send() /receive() operations: receives the message.
*Direct or indirect communication.
PIPES bidirectional, and no parent-child
A pipe acts as a conduit allowing two relationship is required. Once a named pipe
processes to communicate. Pipes were one is established, several processes can use it
of the first IPC mechanisms in early UNIX for communication. In fact, in a typical
systems and typically provide one of the scenario, a named pipe has several writers.
simpler ways for processes to communicate Additionally, named pipes continue to exist
with one another, although they also have after communicating processes have
some limitations. finished. Both UNIX and Windows systems
support named pipes. Named pipes are
Ordinary Pipes
referred to as FIFOs in UNIX systems. Once
allow two processes to communicate in
created, they appear as typical files in the
standard producer consumer fashion; the
file system. A FIFO is created with the mkfifo
producer writes to one end of the pipe(write
() system call and manipulated with the
end) and the consumer reads from the other
ordinary open(), read(), write(), and close ()
end(read end). As a result, ordinary pipes
system calls. It will continue to exist m<til it
are unidirectional, allowing only one-way
is explicitly deleted from the file system.
communication. If two-way communication
Although FIFOs allow bidirectional
is required, two pipes must be used, with
communication, only half-duplex
each pipe sending data in a different
transmission is permitted. If data must
direction. We next illustrate constructing
travel in both directions, two FIFOs are
ordinary pipes on both UNIX and Windows
typically used
systems. In both program examples, one
process writes the message Greetings to the Dining-Philosophers Problem
pipe, while the other process reads this ➢Philosophers spend
message front the pipe. On UNIX systems, their lives alternating
ordinary pipes are constructed using the thinking and eating
function pipe (int fd []) This function creates ➢Don’t interact with
a pipe that is accessed through the int fd [] their neighbors,
file descriptors: fd [0] is the read-end of the occasionally try to pick
pipe, and fd [1] is the write end. up 2 chopsticks (one at a time) to eat from
bowl *Need both to eat, then release both
when done ➢The shared data are:
semaphore chopstick[5]; ➢Where all the
elements of chopstick are initialized to 1.
The structure of Philosopher i:
do {
Named Pipes wait(chopstick[i]);
Ordinary pipes provide a simple wait(chopstick[(i+1) % 5]);
communication mechanism between a pair ...
of processes. However, ordinary pipes exist /* eat for awhile */
only while the processes are communicating ...
with one another. On both UNIX and signal(chopstick[i]);
Windows systems, once the processes have signal(chopstick[(i+1) % 5]);
finished communicating and terminated, the ...
ordinary pipe ceases to exist. Named pipes /* think for awhile */
provide a much more powerful ... } while (true);
communication tool; communication can be

You might also like