Unit 3 Notes
Unit 3 Notes
Process Management
Mr. C. R. Ghuge, Lecturer, Guru Gobind Singh Polytechnic, Nashik.
Unit 3:Process Management
Total Marks:14
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.
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
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:
Events
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.
• 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:
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
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
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.