UNIT III
UNIT III
UNIT III
Chapter - 3
Process Management
2. Why is process creation necessary? State the role of fork process in the context.
Process creation: When a new process is to be added to those currently being managed,
the operatingsystem builds the data structures that are used to manage the process and
allocates address space in mainmemory to the process.
This is the creation of a new process.
Create Process Operating system creates anew process with the specified or default
attributes and identifier.
A process may create several new subprocesses.
Syntax for creating new process is: CREATE (processed, attributes)
Process creation in UNIX and Linux are done through fork() system calls.
When the operating systemcreates a process at the explicit request of another process, the
action is referred to as process spawning.
When one process spawns another, the former is referred to as the parent process, and the
spawned processis referred to as the child process.
The parent may have to partition its resources among its children, or itmay be able to
share some resources among several of its children.
A sub-process may be able to obtain itsresources directly from the operating system. exec
system call used after a fork to replace the process memory space with a new program
Ready State: When the process is loaded into the main memory, it is ready for
execution.this state the process is waiting for processor allocation.
Running State: When CPU is available, system selects one process from main memoryand
executes all the instruction from that process. So when a process is in execution, it is
inrunning state. In single user system, only one process can be in the running state.
Inmultiuser system, there can be multiple processes which are in the running state.
Waiting State: When a process is in execution, it may request for I/O resources. If
theresource is not available, process goes into the waiting state. When the resource
isavailable, the process goes back to ready state.
Terminated State:
When the process completes its execution, it goes into the terminated state. In this state
thememory occupied by the process is released.
Text Segment: The Text segment (the Instruction segment) contains the executable program
code and constant data. The text segment is marked by the operating system as read-only and
cannot be modified by the process. Multiple processes can share the same text segment.
Processes share the text segment if a second copy of the program is to be executed concurrently.
In this setting, the system references the previously loaded text segment with the pointer rather
than reloading a duplicated. If needed, shared text, which is the default when using the C/C++
compiler, can be turned off by using the -N option on the compile time.
Data Segment: The data segment, which is contiguous (in a virtual sense) with the text
segment, can be subdivided into initialized data (e.g. in C/C++, variables that are declared as
static or are static by virtual of their placement) and uninitialized (or 0- initizliazed) data. The
uninitialized data area is also called BSS (Block Started by Symbol). For example, Initialized
Data section is for initialized global variables or static variables, and BSS is for uninitialized.
Stack Segment
The stack segment is used by the process for the storage of automatic identifier, register
variables, and function call information. Stack is basically used to store the temporary values.
The temporary values can be parameter or return values of functions, local variables, addresses
of the return values etc. In the above figure, the stack grows towards the uninitialized data
segment.
The user area: In addition to the text, data, and stack segment, the OS also maintains for each
process a region called the u area (User Area). The u area contains information specific to the
process (e.g. open files, current directory, and signal action, accounting information) and a
system stack segment for process use. If the process makes a system call (e.g., the system call to
write in the function in main), the stack frame information for the system is stored in the system
stack segment. Again, this information is kept by the OS in an area that the process doesn't
normally have access to. Thus, if this information is needed, the process must use special
system call to access it. Like the process itself, the contents of the u area for the process are
paged in and out by the OS.
10. Explain different methods of inter process communication with help ofdiagram
OR
Explain the working of Inter-process communication considering.
1) Shared memory
2) Message passing
1)Shared memory:
In this model, a region of the memory residing in an address space of a process creating a
shared memory segment can be accessed by all processes who want to communicate with
other processes.
All the processes using the shared memory segment should attach to the address space of
the shared memory.
All the processes can exchange information by reading and/or writing data in shared
memory segment.
The form of data and location are determined by these processes who want to
communicate with each other.
These processes are not under the control of the operating system.
The processes are also responsible for ensuring that they are not writing to the same
location simultaneously.
After establishing shared memory segment, all accesses to the shared memory segment
are treated as routine memory access and without assistance of kernel.
2)Message Passing:
In this model, communication takes place by exchanging messages between cooperating
processes.
It allows processes to communicate and synchronize their action without sharing the
same address space.
It is particularly useful in a distributed environment when communication process may
reside on a different computer connected by a network.
Communication requires sending and receiving messages through the kernel.
The processes that want to communicate with each other must have a communication link
between them. Between each pair of processes exactly one communication link exist.
(i) Naming:
Processes which wish to communicate with each other need to know each other with the
name for identification. There are two types of communications :
1. Direct Communication
2. Indirect Communication
In direct communication each process that want to communicate must be explicitly use
name for the sender as well as receiver while communication.
In this type the send( ) and receive( ) primitives are defined as follows:
Send(P,message) – Send message to process P
Receive (Q, message) – Receive a message from process Q.
In an indirect communication the messages could be send or receive from mailboxes or
ports.
A mailbox can be viewed as an object in which messages could be kept or even removed.
Each mailbox is associated with the unique number.
In this type the send( ) and receive( ) primitives are defined as follows:
Send(A,message) – Send message to mailbox A.
Receive (A, message) – Receive a message from mailbox A.
(ii) Synchronization:
Communication between the processes takes place through the system calls.
OS has to maintain proper synchronization between the sending and receiving processes.
To send( ) and receive( ) primitives, a special design is required for the implementation of
these primitives.
These are also known as synchronous and asynchronous communication.
(iii) Buffering:
The communication could be direct or indirect.
The message exchanged by the communicating processes resides or stores in a temporary
queue.
The OS will buffer the messages into the buffers that are created in the system Address
space.
A sender’s message will be copied from the sender’s address space to the next free slot in
the system buffers.
From this system buffer, the messages will be delivered to the receiver process in FCFS
order when receiver process executes receive calls.
3. Economy: - Allocating memory and resources for process creation is costly. Because
threads share resources of the process to which they belong, it is more economical to
create and context-switch threads. Empirically gauging the difference in overhead can be
difficult, but in general it is much more time consuming to create and manage processes
than threads. In Solaris, for example, creating a process is about thirty times slower than
is creating a thread, and context switching is about five times slower.
Kernel Threads:
In systems that use kernel-level threads, the operating system itself isaware of each
individual thread.
Kernel threads are supported and managed directly by the operatingsystem.
A context switch between kernel threads belonging to the sameprocess requires only the
registers, program counter, and stack to bechanged; the overall memory management
information does notneed to be switched since both of the threads share the same
addressspace.
Thus context switching between two kernel threads is slightlyfaster than switching
between two processes.
Kernel threads can be expensive because system calls are required toswitch between
threads. Also, since the operating system isresponsible for scheduling the threads, the
application does not haveany control over how its threads are managed.
16. With neat diagram, explain many to one and many to many multithreading model
with its advantages and disadvantages.
One to One Model:
The one to one model maps each user thread to a single kernel thread.
It provides more concurrency than the many to one model by allowinganother thread to
run when a thread makes a blocking system call.
It also allows multiple threads to run in parallel on multiprocessors.
Whenever user level thread is created, it compulsorily createscorresponding kernel level
thread.
This model is used in Linux & Windows version like 95,97,XP, NT.
Advantages:
o It allows multiple threads to run in parallel on multiprocessors.
o More concurrency
o Less complication in processing
Disadvantages:
Creating a user thread requires creating the corresponding kernelthread.
Creating kernel thread may affect the performance of anapplication.
It reduces performance of the system.
Kernel thread is overhead.
Disadvantages:
One block call from kernel level thread blocks all user level threads.
Cannot take advantage of multiprocessing.