Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

UNIT III

Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

UNIT – III

Chapter - 3
Process Management

1. What is process management? State any four functions of process management.


Process Management:
 The operating system manages many kinds of activities ranging from user programs to
System programslike printer spooler, name servers, file server etc.
 Each of these activities is encapsulated in a process.
 Aprocess includes the complete execution context (code, data, PC, registers, OS
resources in use etc.).
 The major activities/functions of an operating system in regard to process management
are:
1. Creation and deletion of user and system processes.
2. Suspension and resumption of processes.
3. A mechanism for process synchronization.
4. A mechanism for process communication.
5. A mechanism for deadlock handling.

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

3. List and draw a neat labelled diagram of process state.


List:
Each process may be in one of the following states.
 New State: The process is being created.
 Ready State: The process is waiting to be assigned the processor.
 Running State: Instructions from the process are executing.
 Waiting or Blocked: The process is waiting for some event to occur.
 Terminated State: The process has finished execution.
4. State and explain different process state.
Different process states are as follows:
a) New
b) Ready
c) Running
d) Waiting
e) Terminated
New: When a process enters into the system, it is in new state. In this state a process
iscreated. In new state the process is in job pool.

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.

5. Describe how process is terminated.


 A process terminates when it finishes executing its final statement and asks the
operatingsystem to delete it.
 The process may return a status value to its parent process.
 All theresources of the process including physical and virtual memory, open files and
I/O buffers,are deallocated by the operating system.
 For win32- Terminate Process( ) is used to terminate a process.
 For Unix- exit ( ) is used to terminate a process
 A parent may terminate the execution of one of its children for a variety of reason,
such as
 these:
o The child has exceeded its usage of some of the resources that it has been
allocated.
o The task assigned to the child is no longer required.
o The parent is exiting, and the operating system does not allow a child to
continue if thisparent terminates.

6. Describe the following:


(i) Schedulers
(ii) Context switch
(i) Schedulers:
 Schedulers are special system software’s which handles process scheduling in various
ways. A process migrates between the various scheduling queues throughout its life time.
 The operating system must select, for scheduling purposes, processes from these queues
in some fashion.
 The selection process is carried out by the appropriate scheduler.
 Scheduler is the system program which schedules processes from the scheduling queues.
 Their main task is to select the jobs to be submitted into the system and to decide which
process to run.

Schedulers are of three types:


 Long Term Scheduler
 Short Term Scheduler
 Medium Term Scheduler

7. Explain working of CPU switch from process to process with diagram


(ii) Context switch:
 A context switch is the mechanism to store and restore the state or context of a CPU in
Process Control block so that a process execution can be resumed from the same point at
a later time.
 Using this technique a context switcher enables multiple processes to share a single CPU.
 Context switching is an essential part of a multitasking operating system features.
 When the scheduler switches the CPU from executing one process to execute another, the
context switcher saves the content of all processor registers for the process being
removed from the CPU, in its process descriptor.
 The context of a process is represented in the process control block of a process.
 Context switch time is pure overhead.
 Context switching can significantly affect performance as modern computers have a lot
of general and status registers to be saved.
 Content switching times are highly dependent on hardware support

8. Describe Process in memory with diagram.


 Process is program in execution.
 A process in execution needs resources like CPU, memory, I/O.
 Current machines allow several processes to share resources.
 In reality one processor is shared among many processes.
 Process is a program in execution.
 A process does not mean only program but it could contain some part called as text
section.
 It may contain the current activity, represented by the value of the program counter & the
contents of CPU register.
 Another part of process is stack. Stack is basically used to store the temporary values.
 That values can be parameter or return values of functions, local variables, addresses of
the return values etc.
 There is another part called data section. Data section stores the global variable.
 Global variables are accessible throughout the program.
 Sometimes it is necessary to use dynamic memory allocation while executing the
program.
 The heap is a part, which is used for dynamic memory allocation.

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.

9. Describe Process Control Block (PCB) with suitable diagram.


 Each process is represented as a process control block (PCB) in the operating system. It
contains information associated with specific process.
 Process State: It indicates current states of a process. Process state can be new, ready,
running, waiting and terminated.
 Process number: Each process is associated with a unique number.
 Process Counter: It indicates the address of the next instruction to be executed for the
process.
 CPU Registers: The registers vary in number and type depending on the computer
architecture. Register includes accumulators, index registers, stack pointers and general
purpose registers plus any condition code information.
 Memory Management Information: It includes information such as value of base and
limit registers, page tables, segment tables, depending on the memory system used by
OS.
 Accounting Information: This information includes the amount of CPU used, time
limits, account holders, job or process number and so on. It also includes information
about listed I/O devices allocated to the process such as list of open files.

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.

11. Write use of following system calls.


1) fork( )
2) exec( )
3) abort( )
4) end( )

1. fork( ) This system call is used to create a new process.


2. exec( ) This system call is used to replace the process’s memory space with a new
program. It loads a binary file into memory and starts its execution.
3. abort( ) This system call is used to halt process execution abnormally.
4. end( ) This system call is used to halt process execution normally.
12. With neat diagram, explain Message passing system. Also describe the following:
(i) Naming
(ii) Synchronization
(iii) Buffering
Message passing system
 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.

(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.

13. Define synchronization


Explain
(i) Blocking
(ii) Non Blocking in message passing
 Process Synchronization means sharing system resources by processes in such a way
that, concurrent access to shared data is handled thereby minimizing the chance of
inconsistent data.
 Maintaining data consistency demands mechanisms to ensure synchronized execution of
cooperating processes.
 Process Synchronization was introduced to handle problems that arose while multiple
process executions.
 Message passing may be blocking or non-blocking, also known as synchronous and
asynchronous.
 Blocking send: The sending process is blocked until the message is received by
the receiving process or by the mailbox.
 Blocking receives: The receiver blocks until a message is available.
 Non-blocking send: The sending process sends the message and resumes
operation.
 Non-blocking receive: The receiver retrieves either a valid message or a null.

14. Write benefits of using threads.


The benefits of using threads:
1. Responsiveness:- Multithreading an interactive application may allow a program to
continue running even if part of it is blocked or is performing a lengthy operation,
thereby increasing responsiveness to the user. For instance, a multithreaded web browser
could still allow user interaction in one thread while an image was being loaded in
another thread.
2. Resource sharing:-By default, threads share the memory and the resources of the
process to which they belong .The benefit of sharing code and data is that it allows an
application to have several different threads of activity within the same address space.

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.

4. Utilization of multiprocessor architectures: - The benefits of multithreading can be


greatly increased in a multiprocessor architecture, where threads may be running in
parallel on different processors. A single threaded process can only run on one CPU, no
matter how many are available. Multithreading on a multi-CPU machine increases
concurrency.

15. Explain user thread and kernel threads


User-Level Threads:
 A user-level thread is a thread within a process which the OS does notknow about.
 In a user-level thread approach the cost of a context switch betweenthreads less since the
operating system itself does not need to beinvolved–no extra system calls are required.
 A user-level thread is represented by a program counter; registers,stack, and small thread
control block (TCB).
 Programmers typically use a thread library to simplify management ofthreads within a
process.
 Creating a new thread, switching between threads, and synchronizingthreads are done via
function calls into the library.
 This provides aninterface for creating and stopping threads, as well as control overhow
they are scheduled.

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.

Many to one multithreading model:


 This model maps many user level threads to one kernel level thread.
 If user level thread generates blocking system call then it blocks anentire process.
 At a time only one user level thread can access kernel level thread i.emultiple threads
can’t execute in parallel.
 Thread management is done by Thread libraries.
 Example: - Green threads – a thread library available for Solaris usemany-to-one model.
Advantages:-
 It is an efficient model as threads are managed by thread library in userspace.
 Portable: Because user level threads packages are implementedentirely with standard
Unix and POSIX library calls, they are often quiteportable.
 One kernel level thread controls multiple user level threads.
 Easy to do with few system dependencies.

Disadvantages:
 One block call from kernel level thread blocks all user level threads.
 Cannot take advantage of multiprocessing.

Many to many multithreading model:


 This model maps many user level threads to a smaller or equal number of kernel threads.
 Number of kernel threads may be specific to either a particular application or particular
machine.
Advantages:
 Developer can create as many user threads as necessary.
 Threads can run in parallel on a multiprocessor.
 When a thread performs a blocking system call, the kernel can schedule another thread
for execution.
Disadvantage:
 Complex to implement
 Debugging an application is complicated.

You might also like