Unit-II Process Management
Unit-II Process Management
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 1
UNIT-II Process Management
2.3 Inter Process Communication: Shared memory system, Message passing system
2.4 Threads: Benefits, User and Kernel level threads, Multithreading Models: One to One,
Many to One, Many to Many
2.5 Execute process commands like: top, ps, kill, wait, sleep, exit, nice
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 2
UNIT-II Process Management
- A process is a running instance of a program. It is the smallest unit of work that can be
scheduled and executed by the operating system (OS).
- To perform its tasks, a process needs essential resources like:
o CPU time
o Memory
o Files
o I/O devices
- The operating system uses processes to manage the execution of both sequential and concurrent
programs efficiently.
- Process management involves:
o Allocating resources to processes.
o Allowing processes to share and exchange information.
o Protecting process resources from interference by other processes.
o Enabling synchronization among processes.
- OS maintains control over each process using internal data structures that track process state,
resource ownership, and other critical data.
Process:
- Processes progress sequentially, meaning at any given time, only one instruction from the
process executes.
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 3
UNIT-II Process Management
Program Process
An active instance of a program under
A passive set of instructions.
execution.
Stored in secondary storage (e.g., hard disk). Stored in main memory (RAM).
Static entity – does not change during
Dynamic entity – state changes as it executes.
execution.
Does not perform actions by itself. Actively performs tasks via CPU execution.
Occupies fixed space in storage or memory. Continuously changes state during its lifecycle.
May consist of multiple parts or modules. Executes a specific part of the program logic.
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 4
UNIT-II Process Management
A process goes through multiple states from its creation to termination. These states help the operating
system manage processes effectively.
1. New State
2. Ready State
In this state, the process is ready to execute and is waiting in the queue for the CPU to be
assigned.
It has all required resources except the CPU.
It waits its turn as per the scheduling algorithm used by the OS (like FCFS, Round Robin, etc.).
Multiple processes may be in Ready state at the same time.
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 5
UNIT-II Process Management
3. Running State
The process enters this state when it requires an input/output operation or is waiting for an
event to occur.
It cannot continue execution until the event or I/O completes.
While waiting, the process is not consuming CPU time, and is kept aside until it's ready to
proceed.
Example: Waiting for user input, file read/write, etc.
5. Terminated State
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 6
UNIT-II Process Management
- Process State: This specifies the process state i.e. new, ready, running, waiting or terminated.
- Process Number: This shows the number of the particular process.
- Program Counter This contains the address of the next instruction that needs to be executed in
the process.
- Registers: This specifies the registers that are used by the process. They may
include accumulators, index registers, stack pointers, general purpose registers etc.
- List of Open Files: These are the different files that are associated with the process
- CPU Scheduling Information: The process priority, pointers to scheduling queues etc. is
the CPU scheduling information that is contained in the PCB. This may also include any other
scheduling parameters.
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 7
UNIT-II Process Management
- Memory Management Information: The memory management information includes the page
tables or the segment tables depending on the memory system used. It also contains the value of
the base registers, limit registers etc.
- I/O Status Information: This information includes the list of I/O devices used by the process,
the list of files etc.
- Accounting information: The time limits, account numbers, amount of CPU used, process
numbers etc. are all a part of the PCB accounting information.
- Location of the Process Control Block: The process control block is kept in a memory area that
is protected from the normal user access. This is done because it contains important process
information. Some of the operating systems place the PCB at the beginning of the kernel stack for
the process as it is a safe location.
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 8
UNIT-II Process Management
Process Scheduling:
- A part of the Operating System that decides which process should run next on the CPU.
- Process Scheduling is the method by which the operating system decides which process will use
the CPU next.
- It helps in efficient use of the CPU and improves system performance.
- Why is Process Scheduling Important?
- Keeps CPU busy all the time.
- Reduces waiting time for processes.
- Provides fair chances to all processes.
- Improves system response time.
- Increases overall system throughput (number of processes completed).
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 9
UNIT-II Process Management
Scheduling Queues:
- All PCBs (Process Scheduling Blocks) are kept in Process Scheduling Queues by the OS.
- Each processing state has its own queue in the OS, and PCBs from all processes in the same
execution state are put in the very same queue.
- A process’s PCB is unlinked from its present queue and then moved to its next state queue when
its status changes.
- The following major process scheduling queues are maintained by the Operating System:
1. Job Queue
2. Ready Queue
Contains all processes that are ready to run and waiting for CPU time.
Managed by the Short-Term Scheduler.
Example: When a process is in memory but waiting for CPU.
4. Waiting Queue
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 10
UNIT-II Process Management
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 11
UNIT-II Process Management
Types of Schedulers:
- Schedulers are computer programmes that manage process scheduling in a variety of ways.
- Their primary responsibility is to choose which jobs to submit into the system and which
processes to run.
- There are three types of schedulers:
o Long-Term Scheduler
o Short-Term Scheduler
o Medium-Term Scheduler
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 12
UNIT-II Process Management
- Example: When a process completes its time slice or is blocked for I/O, the short-term scheduler
chooses the next process to run.
3. Medium-Term Scheduler
- The medium-term scheduler is responsible for swapping processes in and out of main memory to
manage the degree of multiprogramming and improve system performance.
- It can temporarily remove processes from memory (swap them out) to free up resources and bring
them back later (swap them in) when resources are available.
- It helps to handle situations where the system has too many processes in memory, causing
performance degradation.
- Example: If the system is overloaded, the medium-term scheduler might swap out some
processes to secondary storage, allowing other processes to run.
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 13
UNIT-II Process Management
Speed is lesser than short term Speed is fastest among other Speed is in between both short and
scheduler two long term scheduler.
It controls the degree of It provides lesser control over It reduces the degree of
multiprogramming degree of multiprogramming multiprogramming.
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 14
UNIT-II Process Management
Context Switch:
- Context Switching is the process where the CPU switches from running one process to another.
- It saves the current process's state and loads the next process's state.
- Why Context Switching Occurs?
o When a process is blocked (waiting for I/O).
o Time slice expires in pre-emptive scheduling (e.g., Round Robin).
o A higher priority process arrives.
o Voluntary yield by the process itself.
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 15
UNIT-II Process Management
Supports multitasking.
Improves CPU utilization.
Allows responsive systems (important for real-time OS).
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 16
UNIT-II Process Management
- Advantages of IPC
- Disadvantages of IPC
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 17
UNIT-II Process Management
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 18
UNIT-II Process Management
B. Indirect Communication
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 19
UNIT-II Process Management
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 20
UNIT-II Process Management
Threads:
1. Faster Execution – Threads are lighter than processes; context switching is quicker.
2. Efficient Resource Sharing – Threads share memory, so they communicate faster than
processes.
3. Multitasking – Multiple threads can run at the same time (parallel execution).
4. Better Use of Multi-core CPUs – Threads can run on different cores for improved
performance.
- Advantages of Threads
1. Faster Execution
o Threads run parts of a program simultaneously, improving performance.
2. Efficient CPU Usage
o On multi-core systems, threads can run in parallel on different CPUs.
3. Less Resource Usage
o Threads share memory of the parent process → need less memory than processes.
4. Faster Creation
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 21
UNIT-II Process Management
o Threads are easier and quicker to create and manage than full processes.
5. Improved Application Responsiveness
o Applications stay responsive (don’t freeze) while performing background tasks.
o Example: You can type in Word while it auto saves in another thread.
6. Simplified Communication
o Threads of the same process share data → no complex IPC (inter-process
communication) needed.
7. Better for Concurrent Programming
o Threads allow tasks like input, output, and computation to happen at the same time.
8. Low Context Switching Time
o Switching between threads is quicker than switching between processes.
9. Scalability
o Threads help applications scale better on multi-core systems.
10. Cost-effective - Requires less overhead (CPU, memory, resources) than using multiple
processes.
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 22
UNIT-II Process Management
3. It needs more time for work and conception. It needs less time for work and conception.
4. Context switching takes maximum time here. Here, context switching takes minimum time.
8. If one process is problamatic then it will not affect If one thread is problematic then it will affect the
the operation of another process. execution of another process.
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 23
UNIT-II Process Management
Benefits of Threads:
Responsiveness
Threads help applications stay active even if one part is busy or stuck.
Example: A web browser can load videos (one thread) while still allowing you to scroll and type
(another thread).
A server can keep listening for new requests while one thread handles the current one.
Resource Sharing
Economy
Scalability
Threads can share data easily within the same address space.
Thread synchronization makes communication safe and fast.
Useful when large amounts of data need to be shared between tasks.
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 24
UNIT-II Process Management
On single-CPU systems, the CPU quickly switches between threads to create the feel of
parallelism.
Improves use of the processor's full capability.
Enhanced Concurrency
Threads increase concurrency — multiple operations can occur at the same time.
Each thread can run on a different processor in multi-CPU systems.
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 25
UNIT-II Process Management
User Threads:
Advantages:
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 26
UNIT-II Process Management
Disadvantages:
Kernel Threads:
Advantages:
1. The kernel is fully aware of kernel-level threads, so the scheduler handles the process better.
2. The kernel can still schedule another thread for execution if one thread is blocked.
3. This type of thread is suitable for applications that are frequently blocked.
4. Multi-processor applications in kernel-level threads can fully utilize multiprocessing to their
advantage.
Disadvantages:
1. It is slower to create and inefficient.
2. The overhead associated with kernel-level threads requires a thread control block.
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 27
UNIT-II Process Management
3. Kernel-level threads are not generic and are specific to the Operating System.
4. Kernel-level threads are not as easy to manage as user-level threads.
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 28
UNIT-II Process Management
Advantages:
Disadvantages:
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 29
UNIT-II Process Management
Advantages:
- Totally portable.
- Performance is better.
- One kernel thread controls multiple user threads.
- Mainly used in language systems, portable libraries.
Disadvantages:
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 30
UNIT-II Process Management
Advantages:
Disadvantages:
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 31
UNIT-II Process Management
Execute process commands like: top, ps, kill, wait, sleep, exit, nice
PID: Process ID
%CPU: CPU usage
%MEM: Memory usage
COMMAND: Name of the program
Example: top
Use:
2. ps – Process Status
Description:
Common Options:
Example: ps aux
Use:
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 32
UNIT-II Process Management
Example:
kill 1234 # Politely stop process with PID 1234
kill -9 1234 # Forcefully kill process
Use:
Example:
sleep 5 & # Run sleep in background
wait $! # Wait until background process finishes
Use:
Example:
sleep 3 # Waits for 3 seconds
Use:
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 33
UNIT-II Process Management
Example:
exit 0 # Normal successful exit
exit 1 # Exit with error
Use:
Example:
nice -n 10 ./heavy_task.sh
Use:
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 34
UNIT-II Process Management
Summary Table:
nice Run with set priority Lower priority task nice -n 10 command
Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 35