0% found this document useful (0 votes)
12 views35 pages

Unit-II Process Management

Unit II of the document focuses on Process Management in Operating Systems, covering key concepts such as processes, process states, process control blocks, and scheduling. It explains the roles of various types of schedulers and the importance of context switching and inter-process communication. Additionally, it outlines the structure of processes and the resources they require for execution.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views35 pages

Unit-II Process Management

Unit II of the document focuses on Process Management in Operating Systems, covering key concepts such as processes, process states, process control blocks, and scheduling. It explains the roles of various types of schedulers and the importance of context switching and inter-process communication. Additionally, it outlines the structure of processes and the resources they require for execution.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

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

Syllabus: Total Marks:14

2.1 Processes: process state, process control block

2.2 Process Scheduling: scheduling queues, types of schedulers, context switch

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

Introduction to 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:

- A process can be defined as:

 An entity representing the basic unit of work implemented in a system.


 A program under execution that competes for CPU time and other resources.
 Often referred to as a job, task, or unit of work.

- 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

- In memory, a process consists of:

1. Text Section: Contains the program code.


2. Data Section: Stores global and static variables.
3. Heap: Manages dynamic memory allocation via functions like malloc, new, and delete.
4. Stack: Stores local variables, subroutine parameters, return addresses, and temporary data.
5. Program Counter: Contains the address of the current instruction being executed.

- Multiprogramming allows multiple processes to exist simultaneously within the memory.


- However, at any single moment, only one process can execute on the CPU.
- The CPU rapidly switches between processes using context switching, giving the illusion that
multiple processes are running in parallel

Difference between Program & Process:

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

Process States in Operating System:

A process goes through multiple states from its creation to termination. These states help the operating
system manage processes effectively.

1. New State

 This is the initial state of a process.


 The process is being created by the operating system.
 Necessary resources are allocated, but the process has not yet entered the ready queue for
execution.
 Example: When you start an application, it enters the New state first.

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 is in the active execution phase.


 The CPU is currently executing the instructions of this process.
 During this state, the process performs its computations and may also produce outputs.
 Note: At any single instant, only one process can be in Running state on a single-core CPU.

4. Waiting or Blocked 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

 Also called the Completed or Exit State.


 After successful execution or due to errors/failure, the process moves to Terminated state.
 The operating system frees up resources allocated to the process like memory, files, etc.
 The process is now considered dead and is removed from the process table.

Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 6
UNIT-II Process Management

Process Control Block:


- Process Control Block is a data structure that contains information of the process related to it.
- The process control block is also known as a task control block, entry of the process table, etc.
- It is very important for process management as the data structuring for processes is done in terms
of the PCB.
- It also defines the current state of the operating system.
- Structure of the Process Control Block: The process control stores many data items that are
needed for efficient process management. Some of these data items are explained with the help of
the given diagram.

- 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

 Contains all processes in the system.


 As soon as a process is created, it enters the 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.

3. Device Queue (I/O Queue)

 Contains processes waiting for I/O devices (like printer, disk).


 If a process requests I/O, it is moved to the device queue.

4. Waiting Queue

 Sometimes called Blocked Queue.


 Contains processes waiting for some event to occur (like file download completion).

Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 10
UNIT-II Process Management

- Movement Between Queues

 New Process → Job Queue


 When admitted → Ready Queue
 When needs I/O → Device Queue
 After I/O completion → Back to Ready Queue
 When gets CPU → Runs on CPU
 If waiting → Goes to Waiting Queue

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

1. Long-Term Scheduler (Job Scheduler)


- A job scheduler is another name for it.
- A long-term scheduler determines which programs are accepted for processing into the system.
- It picks processes from the queue and then loads them into memory so they can be executed.
- For CPU scheduling, a process loads into memory.
- The long-term scheduler controls the degree of multiprogramming by deciding which processes
are admitted to the system and loaded into memory for execution.
- To maintain a balance between CPU-bound and I/O-bound processes, ensuring efficient resource
utilization.
- It operates relatively slowly compared to other schedulers as it deals with the overall system load.
- Example: It select processes from a job queue on disk and load them into the ready queue in
memory.

2. Short-Term Scheduler (CPU Scheduler)


- CPU scheduler is another name for it.
- Its major goal is to improve system performance according to the set of criteria defined.
- It refers to the transition from the process’s ready state to the running stage.
- The CPU scheduler happens to choose a process from those that are ready to run and then
allocates the CPU to it.
- The short-term scheduler selects which process from the ready queue will be allocated the CPU
next.
- It helps to maximize CPU utilization and minimize response time.
- It operates very frequently and quickly, making decisions in milliseconds.

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

Difference between schedulers:

Long-Term Scheduler Short-Term Scheduler Medium-Term Scheduler

It is a job scheduler It is a CPU scheduler It is a process swapping scheduler.

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.

It is almost absent or minimal in It is also minimal in time


It is a part of Time sharing systems.
time sharing system sharing system

It selects processes from pool It can re-introduce the process into


It selects those processes which
and loads them into memory for memory and execution can be
are ready to execute
execution continued.

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.

- Following Steps done in Context Switching

1. Pause the current process.


2. Save its state (PC, registers) into its PCB.
3. Choose the next process using the scheduler.
4. Load the next process’s state from its PCB.
5. Resume execution of the new process.

- What is Saved During Context Switching?


 Program Counter (PC) – remembers where the process stopped.
 CPU Registers – holds the current process’s working data.
 Process State – stored in Process Control Block (PCB).

Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 15
UNIT-II Process Management

- Advantages of Context Switching

 Supports multitasking.
 Improves CPU utilization.
 Allows responsive systems (important for real-time OS).

- Disadvantages of Context Switching

 Adds CPU overhead (no productive work during switching).


 Too many switches reduce overall system performance.
 Complex to manage efficiently in large systems.

Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 16
UNIT-II Process Management

Inter Process Communication (IPC):

- IPC stands for Inter Process Communication.


- It is the method by which processes exchange data and messages with each other.
- Necessary in multitasking systems where processes need to work together.
- Two main methods of IPC: Shared Memory and Message Passing.

- Why is IPC Needed?


o To share data between processes.
o For synchronization of processes.
o To coordinate actions between different processes.
o To avoid race conditions.

- Example: Uses of IPC

 Chat applications (processes exchanging messages).


 Web servers (handling multiple clients).
 File sharing between different applications.

- Advantages of IPC

 Enables process cooperation.


 Helps in efficient resource sharing.
 Supports modular and distributed systems.

- Disadvantages of IPC

 Can cause synchronization problems (race conditions, deadlocks).


 Overhead in managing communication.

Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 17
UNIT-II Process Management

Shared Memory System:

- A Shared Memory System is a type of Inter Process Communication (IPC) method.


- In this system, multiple processes share a common memory space to exchange data.
- The Operating System sets up a shared memory region in RAM.
- Different processes can read from and write to this memory area.
- The data is not copied between processes, making communication fast.
- It gives Direct access to shared data.
- Processes must use synchronization tools to avoid conflicts.
- Used mainly for fast communication between processes running on the same system.
- Shared Memory is the fastest IPC method, but requires careful synchronization to avoid errors.

- Steps in Shared Memory Communication

1. Process A writes data into shared memory.


2. Process B reads data from shared memory.
3. Synchronization ensures only one process accesses shared data at a time.

- Advantages of Shared Memory

 Fastest IPC method (no need to copy data).


 Suitable for large data exchange.
 Direct communication without kernel involvement after setup.

- Disadvantages of Shared Memory

 Risk of data corruption if synchronization is not used.


 Complex to implement due to manual synchronization.
 Works only for processes running on the same system.

Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 18
UNIT-II Process Management

Message Passing System:

- A Message Passing System is an Inter Process Communication (IPC) method.


- Processes communicate by sending and receiving messages.
- No shared memory is required.
- Each process has a communication channel (like message queue, pipe, or socket).
- Messages are sent through these channels.
- Messages can include simple data or complex objects.

- Types of Message Passing


A. Direct Communication

 Processes send messages directly to each other.


 Requires processes to know each other's identities.

B. Indirect Communication

 Messages are sent via a message queue or mailbox.


 Processes don’t need to know each other.

- Message Passing Methods


Send() Process sends a message.
Receive() Process waits to receive a message.
- Types of Message Communication
Synchronous Sender waits until receiver gets the message.
Asynchronous Sender sends message and continues without waiting.

Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 19
UNIT-II Process Management

- Advantages of Message Passing

 Simple to implement (compared to shared memory).


 Suitable for distributed systems (processes on different machines).
 Less risk of data corruption (no shared memory).
 Processes don’t need to share address space.

- Disadvantages of Message Passing

 Slower than shared memory (data must be copied).


 Communication overhead due to message management.
 Managing message queues can become complex.

Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 20
UNIT-II Process Management

Threads:

- Thread is the smallest unit of execution within a process.


- It is also called a lightweight process.
- Multiple threads can exist inside a single process and share resources.
- A process can have multiple threads, but every thread belongs to only one process.
- If the system supports multithreading, one process can run many threads.
- Threads work best when there is more than one CPU.
- Threads of the same process share:
 Code
 Data
 File system
- Each thread has its own:
 Stack
 Program Counter (PC)
 Registers

- Why Use 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

Difference between Process & Threads:

S.No Process Thread

1. When a program is under execution, then it is A segment of a process is known as thread.


known as a process.

2. It consumes maximum time to stop. It consumes minimum time to stop.

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.

5. It is not that effective in terms of communication. It is effective in terms of communication.

6. It takes more resources. It takes less resources.

7. It is a heavy weight process. It is a light weight process.

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

 Threads of the same process automatically share memory and data.


 No need for complex sharing methods like in processes.
 Makes it easier to manage multiple tasks using the same data.

 Economy

 Creating a thread is faster and cheaper than creating a process.


 Threads use less memory and resources because they share the same memory space.
 Example: In Solaris OS, creating a process is 30x slower than creating a thread.

 Scalability

 On systems with multiple CPUs, different threads can run in parallel.


 A single-threaded process cannot use multiple CPUs effectively.
 Multithreading increases performance and parallelism.

 Better Communication System

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

 Microprocessor Architecture Utilization

 Threads can run on different processors at the same time.

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.

 Minimized System Resource Usage

 Threads use fewer system resources than full processes.


 They are easier to create, manage, and terminate.

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

 Reduced Context Switching Time

 Switching between threads is faster than between processes.


 This is because threads use the same memory space, so less data needs to be saved and restored.

Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 25
UNIT-II Process Management

User Threads:

- User threads are implemented by user-level libraries.


- The operating System doesn't recognize user-level threads directly.
- Implementation of User threads is easy.
- Context switch time is less.
- No hardware support is required for context switching.
- If one user-level thread performs a blocking operation, then the entire process will be blocked.
- Multithreaded applications cannot take full advantage of multiprocessing.
- User-level threads can be created and managed more quickly.
- Any operating system can support user-level threads.
- Simple and quick to create, more portable, does not require kernel mode privileges for context
switching.
- In user-level threads, each thread has its own stack, but they share the same address space.
- User-level threads are more portable than kernel-level threads.

Advantages:

- User level thread can run on any operating system.


- User level threads are fast to create and manage.
- User thread library easy to portable.
- Low cost thread operations are possible.
- A user thread does not require modification to operating system.

Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 26
UNIT-II Process Management

Disadvantages:

- Multithreaded applications cannot take advantage of multiprocessing.


- At most, one user level thread can be in operation at one time.
- If user thread is blocked in the kernel, then entire process is blocked.

Kernel Threads:

- Kernel threads are implemented by Operating System (OS).


- Kernel threads are recognized by Operating System.
- Implementation of Kernel-Level thread is complicated.
- Context switch time is more.
- Hardware support is needed.
- If one kernel thread performs a blocking operation, then another thread can continue execution.
- Kernels can be multithreaded.
- Kernel-level level threads take more time to create and manage.
- Kernel-level threads are operating system-specific.
- The application code doesn't contain thread management code;
- In kernel-level threads have their own stacks and their own separate address spaces, so they are
separated from each other.
- Kernel-level threads can be managed independently, so if one thread crashes, it doesn't
necessarily affect the others.
- It can access to the system-level features like I/O operations.
- Less portable due to dependence on OS-specific kernel implementations.

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.

Difference between user-level thread and kernel level thread.

Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 28
UNIT-II Process Management

Multi-threading model are of three types.

1) Many to many model.


2) Many to one model.
3) one to one model.

1. Many to Many Model


- In this model, we have multiple user threads multiplex to same or lesser number of kernel level
threads.
- Number of kernel level threads are specific to the machine, advantage of this model is if a user
thread is blocked we can schedule others user thread to other kernel thread.
- Thus, System doesn't block if a particular thread is blocked.
- It is the best multi-threading model.

Advantages:

- Many threads can be created as per user’s requirements.


- Multiple kernel can be created.

Disadvantages:

- True concurrency cannot be achieved.


- Multiple threads of kernel are an overhead for OS.
- Performance is less.

Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 29
UNIT-II Process Management

2. Many to One Model


- In this model, we have multiple user threads mapped to one kernel thread.
- In this model when a user thread makes a blocking system call entire process blocks.
- As we have only one kernel thread and only one user thread can access kernel at a time, so multiple
threads are not able access multiprocessor at the same time.
- The thread management is done on the user level so it is more efficient.

Advantages:

- Totally portable.
- Performance is better.
- One kernel thread controls multiple user threads.
- Mainly used in language systems, portable libraries.

Disadvantages:

- Cannot take advantage of parallelism.


- One block thread can block all user threads.

Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 30
UNIT-II Process Management

3. One to One Model


- In this model, one to one relationship between kernel and user thread.
- In this model multiple thread can run on multiple processor.
- Problem with this model is that creating a user thread requires the corresponding kernel thread.
- As each user thread is connected to different kernel, if any user thread makes a blocking system
call, the other user threads won't be blocked.

Advantages:

- Multiple threads can run parallel.


- Less complication in the processing.
- More concurrency because of multiple threads can run in parallel on multiple CPUs.

Disadvantages:

- Kernel thread is an overhead.


- It reduces the performance of system.
- Limiting the number of total threads.
- Thread creation involves light weight process creation.

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

1. top – Real-time Process Viewer


Description:

 Shows live (real-time) information about the system’s processes.


 Continuously updates the screen with process info like CPU usage, memory, PID, and user.
 Helps monitor which processes are consuming the most resources.

Key Info Shown:

 PID: Process ID
 %CPU: CPU usage
 %MEM: Memory usage
 COMMAND: Name of the program

Example: top

 Displays the system processes in a live updating table.

Use:

 Useful for system administrators to monitor performance.

2. ps – Process Status
Description:

 Shows a snapshot of current processes.


 Does not update automatically like top.

Common Options:

 ps: Shows processes of current user.


 ps -e: Shows all processes.
 ps aux: Shows all processes with full details.

Example: ps aux

 Displays a list of all running processes with details.

Use:

 Used to find processes, get PID, or troubleshoot.

Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 32
UNIT-II Process Management

3. kill – Stop a Process


Description:

 Sends a signal to a process to stop it.


 By default, it sends SIGTERM (15) to terminate process politely.
 With -9, sends SIGKILL to forcefully stop a process.

Example:
kill 1234 # Politely stop process with PID 1234
kill -9 1234 # Forcefully kill process
Use:

 Stops programs that are unresponsive or stuck.

4. wait – Wait for Background Process


Description:

 Pauses script execution until a background process completes.


 Often used in shell scripting.

Example:
sleep 5 & # Run sleep in background
wait $! # Wait until background process finishes
Use:

 Used to synchronize tasks in scripts.

5. sleep – Delay Execution


Description:

 Pauses program or script for a certain amount of time.


 Time can be given in seconds, minutes, etc.

Example:
sleep 3 # Waits for 3 seconds
Use:

 Used in testing, automation, or adding delays in scripts.

Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 33
UNIT-II Process Management

6. exit – Exit Shell or Script


Description:

 Used to end a shell session or script.


 Can return a status code:
o 0: Success
o Non-zero: Error or failure

Example:
exit 0 # Normal successful exit
exit 1 # Exit with error
Use:

 Used in shell scripts to indicate success or failure.

7. nice – Run Process with Priority


Description:

 Starts a process with a priority level.


 Priority is called “niceness”:
o Lower value = higher priority
o Higher value = lower priority
o Range: -20 (high) to 19 (low)
 Only root can set negative (high priority) values.

Example:
nice -n 10 ./heavy_task.sh
Use:

 Used to reduce the priority of resource-heavy tasks.

Operating System by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 34
UNIT-II Process Management

Summary Table:

Command Description Use Case Example

top Live process viewer Monitor CPU/memory top

ps Show running processes Find PID or details ps aux

kill Terminate a process Stop stuck process kill -9 1234

wait Wait for background job Synchronize scripts wait $!

sleep Delay execution Pause in script sleep 5

exit Exit shell/script End with status exit 0

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

You might also like