0% found this document useful (0 votes)
13 views

Unit 3 Notes

Uploaded by

rukminigaikar66
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Unit 3 Notes

Uploaded by

rukminigaikar66
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 48

Unit-3

Process Management
Mr. C. R. Ghuge, Lecturer, Guru Gobind Singh Polytechnic, Nashik.
Unit 3:Process Management

CO: Execute process commands for performing process management operations

Total Marks:14

Reference Book Used:Abraham Silberschatz-Operating System Concepts -9th Edition


Q. Define Process with its section
 Process: A program is in execution is a process
 Ex. A word-processing program being run by an individual user on a PC is a
process or
A system task, such as sending output to a printer, can also be a process
 Single Threaded & Multi Threaded

 Process Mgt Purpose: manages many processes running simultaneously on


the operating system.
 Every running software application program has one or more processes
associated with them. Here are the following functions of process
management in the operating system, such as:
 Process creation and deletion.
 Suspension and resumption.
 Synchronization process
 Communication process
Reference Book Used: Abraham Silberschatz-Operating System Concepts -9th Edition-Page No:24 & 25
Concept of Process:
 Process memory is divided
into four sections as shown in
Figure

Reference Book Used: Abraham Silberschatz-Operating System Concepts -9th Edition-Page No:106
1. Stack
 The process Stack contains the temporary data such as method/function
parameters, return address and local variables.

2. Heap
 This is dynamically allocated memory to a process during its run time.

3. Text
 This includes the current activity represented by the value of Program
Counter and the contents of the processor's registers.

4. Data
 This section contains the global and static variables.

Reference Book Used: Abraham Silberschatz-Operating System Concepts -9th Edition-Page No:106
Q. Differentiate Between Process & Thread
Parameter Process Program
Definition A program is in execution A program set of instructions
Nature The process is an instance of the program The nature of the program is passive, so
being executing. it's unlikely to do to anything until it gets
executed.
Resource The resource requirement is quite high in The program only needs memory for
management case of a process. storage.
Overheads Processes have considerable overhead. No significant overhead cost.
Lifespan The process has a shorter and very limited A program has a longer lifespan as it is
lifespan as it gets terminated after the stored in the memory until it is not
completion of the task. manually deleted.
Creation New processes require duplication of the No such duplication is needed.
parent process.
Required Process holds resources like CPU, memory The program is stored on disk in some file
Process address, disk, I/O, etc. and does not require any other resources.
Entity type A process is a dynamic or active entity. A program is a passive or static entity.
Contain A process contains many resources like a A program needs memory space on disk
memory address, disk, printer, etc. to store all instructions.
Q. Draw process state diagram and describe each state.

Process States: As a process executes, it changes state

Reference Book Used: Abraham Silberschatz-Operating System Concepts -9th Edition-Page No:108
Process State Diagram Explanation

Explanation
Step 1 − Whenever a new process is created, it is admitted into
ready state.
Step 2 − If no other process is present at running state, it is
dispatched to running based on scheduler dispatcher.
Step 3 − If any higher priority process is ready, the uncompleted
process will be sent to the waiting state from the running state.
Step 4 − Whenever I/O or event is completed the process will send
back to ready state based on the interrupt signal given by the running
state.
Step 5 − Whenever the execution of a process is completed in
running state, it will exit to terminate state, which is the completion
of process. https://www.tutorialspoint.com/what-are-process-states
States of Process
• 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.

Reference Book Used: Abraham Silberschatz-Operating System Concepts -9th Edition-Page No:107
Q. Draw and explain process control block in detail

Process Control Block (PCB)

 Process Control block is used for


storing the collection of information
about the Processes and this is also
called as the Data Structure which
Stores the information about the
process.

 It created when process created and


removed from memory when process
terminated.
Sr. No PCB Block Explanation
1 Process ID Unique identification for each of the process in the operating system.
2 Process State This information is about the current state of the process. I.e. whether
process is in new, ready, running, waiting or terminated state.
3 Priority Each process is assigned a certain level of priority
4 Program Counter This contains the address of the next instruction to be executed for this
process.
5 CPU Registers CPU registers vary in number and type, depending upon the computer
architectures. These include index registers, stack pointers and general
purpose registers etc.
6 Pointer A pointer to parent process
7 Memory Management This information may include such information as the value of base and
Information limit registers, the page table or the segment table depending upon the
memory system used by operating system.
8 CPU Scheduling This information includes a process priority, pointers to scheduling queues
Information and any other scheduling parameters.
9 Accounting This includes actual CPU time used in executing a process in order to
charge individual user for processor time.
10 I/O Status It includes outstanding I/O request, allocated devices information, pending
operation and so on.
Why is process creation necessary? State the role of fork process in the context

 When a new process is to be added to those currently being managed, the


operating system builds the data structures that are used to manage the process
and allocates address space in main memory to the process. This is the creation
of a new process.
 Create Process Operating system creates a new process with the specified or
default attributes and identifier.
 A process may create several new sub processes.
 Process creation in Unix : fork() system call.
Why is process creation necessary? State the role of fork process in the context
 Process creation in Unix : fork() system call

Fork(): used The fork system call is used to create a new processes.
 The newly created process is the child process.
 The process which calls fork and creates a new process is the parent process.
 The child and parent processes are executed concurrently.
Q. Explain Process Scheduling with diagram:

 Process Scheduling is an OS task that schedules processes of different


states like ready, waiting, and running.
 Process scheduling allows OS to allocate a time interval of CPU execution
for each process.
 Another important reason for using a process scheduling system is that it
keeps the CPU busy all the time.
 This allows you to get the minimum response time for programs.
Process Scheduling:

Events

 Each Rectangular Box represent the queue


(Ready Queue and Devices Queue)
 Circle represents the resources that serves the queues
 & arrow indicate the flow of process in system
Process Scheduling:

Once the process is allocated the CPU


and is executing, one of several events could occur:
New process is initially put • The process could issue an I/O request and then be
in the ready queue. It placed in an I/O queue.
waits there until it is
selected for execution, or • The process could create a new child process and
dispatched. wait for the child’s
termination.
• The process could be removed forcibly from the CPU,
as a result of an interrupt, and be put back in the ready
queue.
Explain Scheduling Queues in OS
 Process Scheduling Queues help you to maintain a distinct queue for each
and every process states and PCBs.
 All the process of the same execution state are placed in the same queue.
 Therefore, whenever the state of a process is modified, its PCB needs to be
unlinked from its existing queue, which moves back to the new state queue.

Three types of operating system queues are:

1. Job queue:
 It helps you to store all the processes in the system.
2. Ready queue:
 This type of queue helps you to set every process residing in the main
memory, which is ready and waiting to execute.
3. Device queues:
 It is a process that is blocked because of the absence of an I/O device.
Q. Define Scheduler with its types
 A scheduler is a special type of system software that handles process
scheduling in various ways.
 It mainly selects the jobs that are to be submitted into the system and decides
whether the currently running process should keep running or not.
 If not then which process should be the next one to run.
 Their main task is to select the jobs to be submitted into the system and to
decide which process to run.

There are three types of schedulers available:


1. Long Term Scheduler
2. Short Term Scheduler
3. Medium Term Scheduler
1. Long Term Scheduler:

 Long term scheduler is also known as a job scheduler.


 This scheduler select process from the queue and loads them into memory
for execution.
 It also controls the degree of multi-programing.
 However, the main goal of this type of scheduler is to offer a balanced mix of
jobs, like Processor, I/O jobs, that allows managing multiprogramming.
2. Short Term Scheduler:
 Short term scheduler is also known as CPU scheduler.
 It selects one of the Jobs from the ready queue and dispatch to the CPU for
the execution.
 A scheduling algorithm is used to select which job is going to be dispatched
for the execution.
 The Job of the short term scheduler can be very critical in the sense that if it
selects job whose CPU burst time is very high then all the jobs after that, will
have to wait in the ready queue for a very long time.
3. Medium Term Scheduler:
 Medium term scheduler takes care of the swapped out processes.
 If the running state processes needs some IO time for the completion then
there is a need to change its state from running to waiting.
 It removes the process from the running state to make room for the other
processes. swapped out processes
 Such processes are the and this procedure is called swapping.
 The medium term scheduler is responsible for suspending and resuming the
processes.
Q. Differentiate between Long-Term, Short-Term and Medium-Term Scheduler
Q. Explain Context Switch in OS with diagram
 Switching the CPU to another process requires saving the state of the old process and loading the
saved state for the new process. This task is known as a Context Switch.
 When the scheduler switches the CPU from one process to another, the state of the current running
process is stored into the PCB and the state for the next process is loaded from its own PCB.
 This is then used to set the PC, registers, etc. Since the register and memory state is saved and
restored in context switches, they are computationally intensive.
 Context switch includes two operations such as state save and state restore
 save operation stores the current information of running process into its PCB
 State restore operation restores the information of process to be executed from its
PCB

Following information is stored during switching:


 Program Counter
 Scheduling information
 Base and limit register value
 Currently used register
 Changed State
 I/O State information
 Accounting information
• Two Processes Po and P1
is in Execution
• Has only one Cpu
• Context Switch from
process po to p1

• When Po is executing allocating the resources(such as CPU..)


• If any interrupt or system call occurs->State Save operation takes place
• Saves the state into PCBo and po will be in idle state

• Now p1 takes palce in state restore operation and reload state from PCB1
• Now p1 is in execution and po is idle
• If any interrupt or system call occurs  State save operation takes place
• Saves the state into PCB1 and p1 is now in idle state
Q. Define Inter-process Communication (IPC)
with its two modes
 IPC stands for Inter-process Communication.
 As the name suggests, it is a technology that enables multiple threads in one
or more processes to communicate with each other.
 It allows the exchange of data between multiple threads of one or different
processes or systems connected via a network.
There are two primary models of inter-process communication:
1. Shared memory
2. Message passing.
 The two communications models are contrasted in the figure below:
1. Message Passing:

 In the message-passing form, communication takes place by way of messages


exchanged among the cooperating processes.
 allows processes to synchronize and communicate with each other
 The processes can communicate with each other without sharing the same
address space
 Usually, the inter-process communication mechanism provides two operations
that are as follows:
 send (message)
 received (message)
2. Shared Memory :

 Inter-process communication (IPC) usually utilizes shared memory


 Processes are communicating using the shared memory address space
 Processes can exchange the information by reading or writing data in shared
memory segment
 The processes are responsible for ensuring that they are not writing on the
same location simultaneously
Q. Define thread
 A thread sometimes called as lightweight process
 A thread is a path of execution within a process
 A traditional (or heavyweight) process has a single thread of control.
 If a process has multiple threads of control, it can do more than one task at a time.
Q. List and explain benefits of Threads:
1. Enhanced (Improved )throughput (output)of the system:
 When the process is split into many threads, and each thread is treated as a
job, the number of jobs done in the unit time increases.
 That is why the throughput of the system also increases.

2. Effective Utilization of Multiprocessor system:


 When you have more than one thread in one process, you can schedule more
than one thread in more than one processor.

3. Faster context switch:


 The context switching period between threads is less than the process context
switching.
 The process context switch means more overhead for the CPU.
4. Responsiveness:
 When the process is split into several threads, and when a thread completes
its execution, that process can be responded to as soon as possible.

5. Communication:
 Multiple-thread communication is simple because the threads share the same
address space, while in process,

6. Resource sharing:
 Resources can be shared between all threads within a process, such as code,
data, and files.
 The stack and register cannot be shared between threads.
 There is a stack and register for each thread.
Q. List and Explain types of Threads:
1. User Level Threads:

 A user-level thread is a thread within a process which the OS does not know
about
 A thread which is implemented by the user known as User Level Thread
 Cost of a context switch between threads less
 since the operating system itself does not need to be involved–no extra system
calls are required.
 User uses the thread library to simplify the management of threads within a
process
 Creating a new thread, switching between threads, and synchronizing threads are
done via function calls into the thread library

 examples: Java thread


2. Kernel Level Threads:
 In kernel-level threads, the operating system itself is aware of each individual
thread.
 The kernel-level thread is implemented by the operating system.
 The kernel knows about all the threads and manages them.
 The kernel-level thread offers a system call to create and manage the threads
from user-space.
 The implementation of kernel threads is more difficult than the user thread.
 Context switch time is longer in the kernel thread.
 Kernel threads can be expensive because system calls are required to switch
between threads
 Also, since the operating system is responsible for scheduling the threads, the
application does not have any control over how its threads are managed.
 Example: Window 2000
Q. Differentiate between Process and Thread
Comparison Basis Process Thread
A process is a program under execution i.e an A thread is a lightweight process that can be
Definition
active program. managed independently by a scheduler.

Processes require more time for context Threads require less time for context switching as
Context switching time
switching as they are more heavy. they are lighter than processes.
Processes are totally independent and don’t A thread may share some memory with its peer
Memory Sharing
share memory. threads.
Communication between processes requires Communication between threads requires less
Communication
more time than between threads. time than between processes.
If a process gets blocked, remaining processes If a user level thread gets blocked, all of its peer
Blocked
can continue execution. threads also get blocked.
Threads generally need less resources than
Resource Consumption Processes require more resources than threads.
processes.
Individual processes are independent of each Threads are parts of a process and so are
Dependency
other. dependent.
Processes have independent data and code A thread shares the data segment, code segment,
Data and Code sharing
segments. files etc. with its peer threads.

All the different processes are treated All user level peer threads are treated as a single
Treatment by OS
separately by the operating system. task by the operating system.

Time for creation Processes require more time for creation. Threads require less time for creation.

Time for termination Processes require more time for termination. Threads require less time for termination.
Q. Differentiate between User Level and Kernel Level Thread
User level thread Kernel level thread
User threads are supported above the kernel and are Kernel threads are supported directly by the operating
implemented by a thread library at the user level. The system.
library provides support for thread creation,
The kernel performs thread creation, scheduling, and
scheduling, and management with no support from the
management in kernel space.
kernel.
When threads are managed in user space, each process No run-time system is needed in each. Also, there is no
needs its own private thread table to keep track of the thread table in each process. Instead, the kernel has a
threads in that process thread table that keeps track of all the threads in the
system.
User-level threads requires non-blocking systems call, Kernel threads do not require any new, non-blocking
that means a multithreaded kernel. Otherwise, entire system calls. If one thread in a process causes a page fault,
process will blocked in the kernel, even if there are the kernel can easily check to see if the process has any
runnable threads left in the processes. For example, if other runnable threads, and if so, run one of them while
one thread causes a page fault, the process blocks. waiting for the required page to be brought in from the
disk.
User-level threads are generally fast to create and The kernel-level threads are slow and inefficient. For
manage instance, threads operations are hundreds of times slower
than that of user-level threads.
User level thread is generic and can run on any Kernel level thread is specific to the operating system.
operating system.
Example: User-thread libraries include POSIX Example: Windows NT, Windows 2000, Solaris 2, BeOS,
Pthreads, Mach C-threads, and Solaris 2 UI-threads. and Tru64 UNIX (formerly Digital UNIX)-support kernel
threads.
Q. Explain Multithreading Models with types
 Multithreading allows the application to divide its task into individual threads.
 In multi-threads, the same process or task can be done by the number of threads,
or we can say that there is more than one thread to perform the task in
multithreading.
 With the use of multithreading, multitasking can be achieved.

Multithreading models:-
1. Many-to-One
2. One-to-One
3. Many-to-Many
1. Many to One Multithreading Model:
Many-to-One: - This model maps many user level threads to one kernel level thread.
Thread management is done by thread library in user space.
Advantages:-
It is an efficient model as threads are managed by thread library in user space.
Disadvantages:-
• Only one thread can access the kernel at a time, so multiple threads are unable to run in
parallel on microprocessor.
• If a thread makes a blocking system call then the entire process will be block.
Example: - Green threads – a thread library available for Solaris use many-to-one model.

Or
2. One to One Multithreading Model:
One-to-One: It maps each user level thread to a kernel level thread. Even one thread makes a
blocking call; other thread can run with the kernel thread.
Advantages:-
• It allows multiple threads to run in parallel on multiprocessors.
Disadvantages:-
• Creating a user thread requires creating the corresponding kernel thread.
• Creating kernel thread may affect the performance of an application.
Example: - Linux, Windows OS including Win 95, 98, NT 2000, and XP implement the one-to-one
model.
Or
3. Many to Many Multithreading Model:

 In this type of model, there are several user-level threads and several kernel-
level threads.
 The number of kernel threads created depends upon a particular application.
 The developer can create as many threads at both levels but may not be the
same.
 The many to many model is a compromise between the other two models.
 In this model, if any thread makes a blocking system call, the kernel can
schedule another thread for execution.
Or
Q. Explain ps command in Linux with Examples

• Linux provides us a utility called ps for viewing information related with the processes on a system
• PS is a Process State: ps command is used to list the currently running processes and their PIDs along with some
other information depends on different options.
Syntax –
ps [options]
Options for ps Command :
•Simple process selection : Shows the processes for the current shell –
[root@rhel7 ~]# ps
PID TTY TIME CMD
12330 pts/0 00:00:00
bash21621 pts/0 00:00:00 ps

Result contains four columns of information.


Where,
PID – the unique process ID
TTY – terminal type that the user is logged into
TIME – amount of CPU in minutes and seconds that the process has been running
CMD – name of the command that launched the process.
•View Processes : View all the running processes use either of the following option with ps –
ps –A
ps -e
•View Processes not associated with a terminal : View all processes except both session leaders and
processes not associated with a terminal.
ps -a
PID TTY TIME CMD
27011 pts/0 00:00:00 man
27016 pts/0 00:00:00 less
27499 pts/1 00:00:00 ps
•View all the processes except session leaders :
ps -d
•View all processes except those that fulfill the specified conditions (negates the selection) :
Example – If you want to see only session leader and processes not associated with a terminal. Then, run
[ ps -a –N
OR
ps -a --deselect
•View all processes associated with this terminal :
ps -T
•View all the running processes :
ps -r
•View all processes owned by you : Processes i.e same EUID as ps which means runner of the ps command,
root in this case –
ps -x

Wait PID
Sleep 10
(Delay 10 sec)
Exit
Kill PID
Important Questions
Unit No:03 Process Management
Q.N Question
1 Define Thread.
2 List different multithreading model.
3 Define context switch.
4 Draw process state diagram.
5 Define Process.
6 Write syntax of following commands: (i) Sleep (ii) Kill
7 Define Scheduling Queue.
Unit No:03 Process Management
Q.N Question
1 Draw and Explain PCB in detail.
2 Draw and Explain Inter-process Communication.
3 Explain different process states with neat diagram.
4 Compare Long, Short, Middle term scheduler.
5 Explain ‘PS’ command with any four options.
Q.N Question
1 Explain Multithreading model with diagram.

You might also like