OS Process
OS Process
Process Concept:
An Operating system executes a variety of programs via
➢ Batch system – Jobs
➢ Time shared systems - User programs or tasks
➢ Process in Memory:
➢ Heap-It is a memory dynamically allocated during process run time
Process Creation:
➢ Parent process creates children processes which in turn create other
processes and forming a tree of processes.
Possibilities
➢ Resource Sharing: Whenever a parent process creates a child processes these sub processes
can directly attain the required resources from the operating system also it
➢ Parents and children share all resources may be constructed to a subset of the resources of the parent process.
➢ Children share subset of parent’s resources The parent process may have to partition its resources among its
➢
subprocesses, or it can be capable to share some of the parent’s
Bounding the sub process to a sub set of
the parent’s resources avoid any process
parent and child share no resources. resources such as files and memory among the various its child
form overloading the system by creating ➢ Execution: processes. In this case sub processes are allocated the subset of
too many child processes. It helps to parent’s resources.
prevent creation of too many subprocesses
which can be a cause of confusion for
➢ Parents and children execute concurrently
operating system. ➢ Parent waits until children terminate.
➢ Address space:
➢ Child duplicates of parent
➢ Child has a program loaded into it
Instructor: Prof M K Singh, Department of Mathematics and Computing, IIT(ISM) Dhanbad
Operating Systems
Course Code: MCC510
Process Creation:
➢ UNIX example:
➢ fork system call creates new process
➢ The new process is an exact copy of the parent and continues execution
from the same point as its parent.
➢ Exec system call used after a fork to replace the processes memory space
with a new program
➢ The only difference between parent and child is the value returned from the
fork call.
➢ 0 for the child.
➢ the process id (pid) of the child, for the parent.
➢ Using fork and exec we can write a simple command line interpreter.
while (true) {
read_command_line(&command,¶meters);
if(fork()!=0) {
waitpid(-1,&status,0);
} else {
execve(command,parameters,0);
}
}
Process Creation:
A process may be created by another process using fork(). The creating
process is called the parent process and the created process is the child
process. A child process can have only one parent but a parent process may
have many children. Both the parent and child processes have the same
memory image, open files and environment strings. However, they have
distinct address spaces.
Process Scheduling:
➢ Process Scheduling is an OS jobs that schedules processes of different
states. It allows OS to allocate a time interval of CPU execution for each
process. Process scheduling system is used to keeps the CPU busy all the
time.
Process Scheduling Queues:
➢ Job queue - Set of all process in the system
➢ Ready queue - Set of all process in the main memory, ready and waiting to
execute
➢ Device queue - Set of all process waiting for an I/O device
➢ Processes migrate among the various queues.
Schedulers:
Long Term Scheduler(Job Schedular):
➢ Select which processes should be brought into the ready queue
➢ The primary objective is to provide balanced mix of jobs such as I/O
bound and processor bound.
➢ It also control the degree of multiprogramming
Short Term Scheduler(CPU Schedular):
➢ Select which processes should be executed next and allocate to CPU
➢ The main objective is to increase system performance accordance with
chosen set of criteria
➢ It is the change of ready state to running state of the process.
Context Switch:
➢ When CPU switches to another process (Because of an interrupt), the
system must save the state of old process and load the saved state for new
process
➢ Context switch time is overhead and the system does no useful work while
switching
➢ Context switch time is highly dependent on hardware support
➢ When the process is switched, the information stored as
➢ Program counter
➢ Scheduling information
➢ Base and limit register
➢ Currently used register
➢ Changed state
➢ I/O state
➢ Accounting
Message Shared
Passing Memory
Direct Communication:
➢ Processes must name each other explicitly
➢ 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 between every pair of processes that want
to communicate
➢ 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 usually it is bidirectional
Indirect Communication:
➢ Messages are directed and received from mailboxes (referred to Port)
➢ Each mailbox has unique id
➢ Processes can communicate only if they share a mailbox
➢ Send(P, message)-send a message to mailbox P
➢ Receive(P, message)- receive a message from mailbox P
➢ Properties of communication link:
➢ Links is established between a pair of processes only if both have shared
mailbox
➢ A link may be associated with more than two processes
➢ Between each pair of processes, there may be many different links, with each
link corresponding to one mailbox
➢ Mechanism provided by the operating system
➢ Create a new mailbox
➢ Send and receive messages through the mailbox
➢ Destroy the mailbox
Instructor: Prof M K Singh, Department of Mathematics and Computing, IIT(ISM) Dhanbad
Operating Systems
Course Code: MCC510
Message Queues :
➢ A message queue is a linked list of messages stored within the kernel. It is
identified by a message queue identifier. This method offers
communication between single or multiple processes with full-duplex
capacity.
FIFO:
➢ Communication between two unrelated processes. It is a full-duplex
method, which means that the first process can communicate with the
second process, and the opposite can also happen.
Pipe:
➢ Pipe is widely used for communication between two related processes.
This is a half-duplex method, so the first process communicates with the
second process. However, in order to achieve a full-duplex, another pipe is
needed.