0% found this document useful (0 votes)
43 views29 pages

Unit03 Osy (22516)

3rd chapter osy
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)
43 views29 pages

Unit03 Osy (22516)

3rd chapter osy
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/ 29

❖ UNIT 03.

PROCESS MANAGEMENT (22516)

❖ Process

o A process is a program in execution, meaning it’s a running instance of an


application.

o It includes the program code, current activity, and associated resources (like
memory, file handles, and input/output information).

o Processes are managed by the operating system and are allocated CPU time and
resources to run smoothly.

❖ Process State

1. Definition and Explanation

o A process state represents the current status of a process during its execution.

o Processes change states depending on events like starting, waiting, or completing a


task.

o Key states include New, Ready, Running, Waiting, and Terminated.

2. Diagram of Process States

Fig.(a) Process State

Diploma Helper. Feel free to DM us at. 8698079745


❖ UNIT 03. PROCESS MANAGEMENT (22516)

3. Diagram Explanation

o The diagram shows how processes transition between states:

▪ New: The process is just created and getting ready to enter the system.

▪ Ready: The process is waiting in line to get CPU time to start executing.

▪ Running: The process is currently using the CPU and actively executing
instructions.

▪ Waiting: The process has paused because it needs something (like


input/output) before it can continue.

▪ Terminated: The process has finished all its tasks and is now complete.

4. Real-Life Example

o Think of a printing task:

▪ When you start printing, the task is New.

▪ Waiting for the printer to be available puts the task in Waiting.

▪ The task Runs when the printer starts printing.

▪ Terminates when printing completes.

5. Advantages

o Allows efficient management of multiple tasks.

o Helps allocate resources based on process requirements.

o Ensures fair execution by managing priorities.

o Reduces CPU idle time with proper scheduling.

6. Disadvantages

o Process state management can be complex.

o Requires significant memory for tracking states.

o Potential delays due to waiting for resources.

o Resource allocation can cause overhead in some cases.

Diploma Helper. Feel free to DM us at. 8698079745


❖ UNIT 03. PROCESS MANAGEMENT (22516)

❖ Process Control Block (PCB)

1. Definition and Explanation

o PCB is a data structure used by the operating system to store important information
about each process.

o It keeps track of details such as process ID, current state, and resources allocated to
the process.

o PCBs help the operating system manage and control multiple processes effectively.

2. Diagram of Process Control Block (PCB)

Fig.(b) Process Control Block (PCB)

3. Diagram Explanation

o Process ID: A unique identifier assigned to each process.

o Process State: Current status of the process (e.g., Ready, Running, Waiting).

o Program Counter: Keeps track of the next instruction to execute.

o CPU Registers: Stores intermediate data needed by the process.

o Memory Management Info: Details about memory allocated to the process.

o I/O Status: Information on I/O devices assigned to the process.

o Accounting Info: Tracks resources used, time taken, and more for process control.

Diploma Helper. Feel free to DM us at. 8698079745


❖ UNIT 03. PROCESS MANAGEMENT (22516)

4. Real-Life Example

o Imagine you’re handling several tasks at work (like emails, reports, meetings). Each
task has a “task file” with notes about what stage it’s in, what resources it needs (e.g.,
specific files), and what’s next. The PCB functions as this task file, organizing essential
details for each task (or process) so the OS can manage them easily.

5. Advantages

o Helps the OS keep track of all active processes.

o Saves the state of processes when switching between them.

o Provides a quick way to resume a process from where it left off.

o Efficiently allocates resources based on process needs.

6. Disadvantages

o Consumes memory to store details for each process.

o Slows down system performance if there are too many PCBs to manage.

o Requires continuous updating, adding to system overhead.

o Errors in PCB management can lead to incorrect process handling.

Diploma Helper. Feel free to DM us at. 8698079745


❖ UNIT 03. PROCESS MANAGEMENT (22516)

❖ Scheduling Queue

1. Definition and Explanation

o A scheduling queue is a collection of processes waiting for certain CPU actions (like
execution, I/O) to continue.

o The operating system uses these queues to manage processes based on their current
needs and states.

o Key types of scheduling queues include the Ready Queue, Job Queue, and Device
(I/O) Queue.

2. Diagram of Scheduling Queue

Fig.(c) Scheduling Queues

3. Diagram Explanation

o Job Queue: Contains all processes that are currently in the system, either waiting to
start or actively being managed.

o Ready Queue: Holds processes that are ready to use the CPU and waiting for their
turn.

o Device (I/O) Queue: Contains processes that are waiting for I/O operations to
complete, such as reading from or writing to storage.

Diploma Helper. Feel free to DM us at. 8698079745


❖ UNIT 03. PROCESS MANAGEMENT (22516)

4. Real-Life Example

o Imagine a customer service centre where:

▪ The Job Queue is like a waiting area for all customers entering the centre.

▪ The Ready Queue is for customers next in line for an available service desk.

▪ The Device Queue is like a separate line for customers waiting on specific
assistance, such as using a special service or machine.

5. Advantages

o Helps organize and prioritize processes, improving system efficiency.

o Allows fair access to CPU and resources among processes.

o Manages high volumes of processes without system overload.

o Optimizes performance by scheduling tasks based on availability and priority.

6. Disadvantages

o Excessive queueing can cause delays, leading to a slower response time.

o High memory usage if there are too many processes in queues.

o Requires efficient algorithms; otherwise, queues can become bottlenecks.

o Managing multiple queues adds complexity to the system.

Diploma Helper. Feel free to DM us at. 8698079745


❖ UNIT 03. PROCESS MANAGEMENT (22516)

❖ Schedulers

1. Definition and Explanation

o Schedulers are system programs that manage the order in which processes are
executed in an operating system.

o They select processes from queues and assign them to the CPU for processing.

o Types of schedulers include Long-Term Scheduler (Job Scheduler), Short-Term


Scheduler (CPU Scheduler), and Medium-Term Scheduler.

2. Diagram of Schedulers

Fig.(d) Schedulers

3. Diagram Explanation

o Long-Term Scheduler: Decides which processes enter the system for processing; it
controls the Job Queue by selecting new jobs.

o Short-Term Scheduler: Chooses processes from the Ready Queue to run on the CPU;
it works more frequently and is responsible for allocating CPU time.

o Medium-Term Scheduler: Manages the Suspended Queue by swapping out


processes to control the number of active processes in memory, improving
multitasking.

Diploma Helper. Feel free to DM us at. 8698079745


❖ UNIT 03. PROCESS MANAGEMENT (22516)

4. Real-Life Example

o Imagine a restaurant kitchen:

▪ The Long-Term Scheduler is like the head chef deciding which orders to start
based on available ingredients.

▪ The Short-Term Scheduler is the line cook preparing meals one by one in the
order they're ready to be cooked.

▪ The Medium-Term Scheduler is the chef who temporarily stops work on


some dishes to keep up with high-priority orders, resuming later.

5. Advantages

o Optimizes system performance by efficiently managing CPU time and process flow.

o Helps maintain a balanced workload by deciding how many processes can run
simultaneously.

o Reduces idle time by promptly assigning tasks to the CPU.

o Improves memory usage by managing process suspensions effectively.

6. Disadvantages

o Complex to implement, as schedulers must prioritize processes effectively.

o Requires careful tuning to avoid overloading the CPU or memory.

o May cause delays for lower-priority processes due to resource allocation.

o High system overhead due to constant decision-making and process switching.

Diploma Helper. Feel free to DM us at. 8698079745


❖ UNIT 03. PROCESS MANAGEMENT (22516)

❖ Context Switch

1. Definition and Explanation

o A context switch is the process of saving a currently running process’s state so the
CPU can switch to another process.

o The operating system saves information like the program counter, CPU registers, and
other details in the Process Control Block (PCB).

o Context switches allow multiple processes to run efficiently by alternating between


them.

2. Diagram of Context Switch

Fig.(e) Context Switch

3. Diagram Explanation

o Process A State Saved: The system saves all of Process A's information (like registers
and program counter) to its PCB.

o CPU Switches to Process B: The saved state of Process B is loaded from its PCB.

o Resuming Execution: The CPU starts executing Process B from where it left off,
allowing both processes to be managed without losing progress.

Diploma Helper. Feel free to DM us at. 8698079745


❖ UNIT 03. PROCESS MANAGEMENT (22516)

4. Real-Life Example

o Imagine pausing a movie on one streaming app to switch to another. You save the
position in the first app, start a new movie on the second app, and can later resume
from the exact place in the first movie. This is similar to how a context switch
temporarily pauses one process to resume another.

5. Advantages

o Enables multitasking by allowing multiple processes to share CPU time.

o Maximizes CPU efficiency by reducing idle time.

o Ensures fair allocation of CPU resources among processes.

o Helps in implementing priorities among processes for smoother system


performance.

6. Disadvantages

o Context switching adds overhead to the CPU, as saving and loading states takes time.

o Too many switches can slow down the overall performance.

o Increases memory usage, as each process's state must be stored.

o Frequent switches can lead to resource contention, causing delays.

Diploma Helper. Feel free to DM us at. 8698079745


❖ UNIT 03. PROCESS MANAGEMENT (22516)

❖ Inter Process Communication (IPC)

1. Introduction

o IPC refers to the methods used by processes to communicate and synchronize their
actions.

o It enables processes to share data and signals, facilitating cooperation and


coordination.

o IPC is essential in multi-process environments to ensure data integrity and efficient


resource management.

2. Diagram of IPC

Fig.(f) Inter Process Communication (IPC)

3. Diagram Explanation

o The diagram illustrates two main IPC methods:

▪ Message Passing: Processes send and receive messages to communicate,


which can occur across different address spaces.

▪ Shared Memory : Multiple processes access the same memory space to read
and write data.

Diploma Helper. Feel free to DM us at. 8698079745


❖ UNIT 03. PROCESS MANAGEMENT (22516)

◆ Shared Memory System

1. Definition and Explanation

o A shared memory system allows multiple processes to access a common memory


space to exchange information.

o It is one of the fastest IPC methods since data does not need to be copied between
the memory of different processes.

o Synchronization mechanisms (like semaphores or mutexes) are often used to control


access and prevent conflicts.

2. Diagram of Shared Memory System

Fig.(g) Shared Memory System

3. Diagram Explanation

o Shared Memory Area: A designated section of memory accessible by all participating


processes.

o Processes can read from and write to this shared area, enabling quick data exchange.

Diploma Helper. Feel free to DM us at. 8698079745


❖ UNIT 03. PROCESS MANAGEMENT (22516)

4. Real-Life Example

o Think of a shared whiteboard in a meeting room. Everyone can write on it, and
anyone can read what others have written at any time.

5. Advantages

o Fast data transfer, as no copying of data is needed.

o Efficient use of memory since data is shared instead of duplicated.

o Suitable for applications requiring high-speed data access.

6. Disadvantages

o Requires careful synchronization to avoid data corruption.

o Debugging can be challenging due to shared access.

o Memory management is more complex compared to other methods.

Diploma Helper. Feel free to DM us at. 8698079745


❖ UNIT 03. PROCESS MANAGEMENT (22516)

◆ Message Passing System

1. Definition and Explanation

o A message passing system allows processes to communicate by sending and


receiving messages.

o It is useful for communication between processes running on different machines or


in different address spaces.

o This method does not require shared memory, making it more flexible and easier to
manage in some scenarios.

2. Diagram of Message Passing System

Fig.(h) Message Passing System

3. Diagram Explanation

o Message Queue: A queue that stores messages sent from one process to another
until they are received.

o Processes use this queue to send and retrieve messages, allowing for asynchronous
communication.

Diploma Helper. Feel free to DM us at. 8698079745


❖ UNIT 03. PROCESS MANAGEMENT (22516)

4. Real-Life Example

o Imagine sending a letter in the mail. You write your message, put it in an envelope,
and send it off. The recipient checks their mailbox and reads your message when
they receive it.

5. Advantages

o Easy to implement and manage, especially in distributed systems.

o Provides clear communication pathways, enhancing modularity.

o Reduces the chance of data corruption since processes do not share memory
directly.

6. Disadvantages

o Slower than shared memory due to message copying and context switching.

o Increased overhead for message management.

o Requires proper handling of message order and reliability to ensure all messages are
received.

Diploma Helper. Feel free to DM us at. 8698079745


❖ UNIT 03. PROCESS MANAGEMENT (22516)

❖ Threads

1. Definition and Explanation

o A thread is the smallest unit of processing that can be scheduled by an operating


system.

o Threads are components of a process, allowing multiple operations to run


concurrently within a single process.

o They share the same memory space but can execute independently, improving
efficiency.

2. Diagram of Threads

Fig.(i) Threads

3. Diagram Explanation

o Process: Represents a running program that contains multiple threads.

o Threads: Each thread can execute different parts of the program simultaneously
while sharing resources like memory.

Diploma Helper. Feel free to DM us at. 8698079745


❖ UNIT 03. PROCESS MANAGEMENT (22516)

◆ Benefits of Threads

1. Increased Responsiveness

o Threads allow applications to remain responsive, as tasks can run in the background
while the user interacts with the program.

2. Resource Sharing

o Threads within the same process share memory and resources, making
communication between them easier and faster.

3. Efficient CPU Utilization

o Threads can be scheduled on multiple CPUs or cores, allowing better CPU utilization
and faster execution.

4. Simplified Program Structure

o Using threads can make the design of complex applications simpler, allowing
developers to break down tasks into smaller, manageable units.

5. Lower Overhead

o Creating and managing threads typically requires less overhead than creating and
managing processes.

◆ User Threads

1. Definition and Explanation

o User threads are managed at the user level by a thread library, not by the operating
system.

o The user-level thread library provides functions to create, manage, and schedule
threads.

o They are typically faster to create and switch between than kernel threads because
no system calls are involved.

2. Advantages

o Quick thread creation and context switching.

o Less overhead since they don’t require kernel mode operations.

Diploma Helper. Feel free to DM us at. 8698079745


❖ UNIT 03. PROCESS MANAGEMENT (22516)

o Portability across different operating systems since they rely on user-level libraries.

3. Disadvantages

o The operating system is unaware of user threads, leading to inefficient scheduling.

o If one thread blocks, all threads within the same process may also block.

o Limited ability to take advantage of multiple processors.

◆ Kernel Threads

1. Definition and Explanation

o Kernel threads are managed directly by the operating system kernel.

o The kernel handles scheduling, switching, and management of these threads, making
them visible to the operating system.

2. Advantages

o The operating system can schedule kernel threads across multiple processors,
improving performance.

o If one thread blocks, the kernel can schedule another thread from the same process
to continue execution.

o Better integration with system resources, allowing efficient management of CPU


time.

3. Disadvantages

o Higher overhead due to the involvement of the kernel in thread management.

o Slower to create and manage compared to user threads because of system calls.

o More complex management as the kernel needs to maintain information about all
threads.

Diploma Helper. Feel free to DM us at. 8698079745


❖ UNIT 03. PROCESS MANAGEMENT (22516)

Diploma Helper. Feel free to DM us at. 8698079745


❖ UNIT 03. PROCESS MANAGEMENT (22516)

❖ Multithreading Models

1. Definition and Explanation

o Multithreading models define how threads are mapped to processes and how they
interact with the operating system.

o Different models affect the performance, complexity, and responsiveness of


applications.

2. Diagram of Multithreading Models

Fig.(j) Multithreading Model

3. Diagram Explanation

o The diagrams for each model illustrate how threads are associated with processes,
with varying degrees of mapping and management by the operating system.

Diploma Helper. Feel free to DM us at. 8698079745


❖ UNIT 03. PROCESS MANAGEMENT (22516)

◆ 1. One-to-One Model

1. Definition and Explanation

o In the One-to-One model, each user thread is mapped to a unique kernel thread.

o This model allows multiple threads to run in parallel on multi-core processors.

o It provides better performance for CPU-bound tasks due to efficient use of system
resources.

2. Diagram

Fig.(k) One-to-One

3. Advantages

o Improved concurrency and responsiveness since multiple threads can be scheduled


independently.

o Kernel-level scheduling allows for efficient management of CPU resources.

o Each thread can be assigned different priorities, allowing better control over
execution.

4. Disadvantages

o Higher overhead due to the need for managing multiple kernel threads.

o Resource-intensive, as each thread consumes kernel memory and resources.

o Limited by the maximum number of threads the operating system can handle.

Diploma Helper. Feel free to DM us at. 8698079745


❖ UNIT 03. PROCESS MANAGEMENT (22516)

◆ 2. Many-to-One Model

1. Definition and Explanation

o In the Many-to-One model, multiple user threads are mapped to a single kernel
thread.

o The thread library is responsible for managing the scheduling and execution of user
threads.

2. Diagram

Fig.(l) Many-to-One

3. Advantages

o Lower overhead as only one kernel thread is required for many user threads.

o Easier to implement and manage, particularly for simple applications.

o Lightweight, as it requires fewer system resources compared to One-to-One.

4. Disadvantages

o Limited concurrency since all user threads are managed by a single kernel thread; if
one thread blocks, all threads in the process are blocked.

o Cannot utilize multiple processors effectively, leading to inefficient CPU usage.

o The operating system cannot perform kernel-level scheduling for user threads.

Diploma Helper. Feel free to DM us at. 8698079745


❖ UNIT 03. PROCESS MANAGEMENT (22516)

◆ 3. Many-to-Many Model

1. Definition and Explanation

o In the Many-to-Many model, multiple user threads can be mapped to multiple kernel
threads.

o This model allows the operating system to dynamically manage the number of kernel
threads and user threads.

2. Diagram

Fig.(m) Many-to-Many

3. Advantages

o Flexibility to utilize multiple processors effectively by allowing many user threads to


run in parallel.

o Improved performance since the operating system can schedule user threads onto
available kernel threads.

o Enhanced responsiveness, as one blocking user thread does not affect the execution
of others.

4. Disadvantages

o Increased complexity in implementation and management of threads.

o Overhead associated with managing multiple kernel threads and user threads.

o Requires sophisticated scheduling algorithms to efficiently manage resource


allocation

Diploma Helper. Feel free to DM us at. 8698079745


❖ UNIT 03. PROCESS MANAGEMENT (22516)

❖ Execute Process Commands


◆ 1. ps Command
1. Explanation

o The ps command displays information about active processes, including their process
ID (PID), status, CPU usage, and more.

2. Syntax

o ps [options]

3. Uses

o To monitor running processes.

o To check memory and CPU usage of processes.

o To identify PIDs for managing processes with other commands.

4. Example

o ps -aux

o This command shows a detailed list of all processes running on the system, with
details on CPU and memory usage.

◆ 2. wait Command
1. Explanation

o The wait command pauses the execution of a script or command until a specific
background process completes.

2. Syntax

o wait [PID]

3. Uses

o To synchronize the execution of processes in a script.

o To ensure that a child process finishes before moving to the next command.

4. Example

o wait $pid

o This command waits for the process with the specified PID to finish before
proceeding.

Diploma Helper. Feel free to DM us at. 8698079745


❖ UNIT 03. PROCESS MANAGEMENT (22516)

◆ 3. sleep Command
1. Explanation

o The sleep command pauses the execution of a command or script for a specified
amount of time.

2. Syntax

o sleep [number][s/m/h/d]
o [number] specifies the amount of time to wait, and [s/m/h/d] denotes seconds,
minutes, hours, or days.

3. Uses

o To add delays in scripts.

o To prevent tasks from starting immediately or too frequently.

4. Example

o sleep 5s

o This command pauses the execution for 5 seconds.

◆ 4. kill Command
1. Explanation

o The kill command sends a specified signal to a process, typically to terminate or stop
it.

2. Syntax

o kill [signal] PID

o [signal] is the type of termination (like -9 for forceful kill), and PID is the process ID.

3. Uses

o To terminate unresponsive or unnecessary processes.

o To control process execution by sending different signals.

4. Example

o kill -9 1234
o This command forcefully terminates the process with PID 1234.

Diploma Helper. Feel free to DM us at. 8698079745


❖ UNIT 03. PROCESS MANAGEMENT (22516)

◆ 5. exit Command
1. Explanation

o The exit command terminates the execution of a shell script or closes a terminal
session.

2. Syntax

o exit [status]

o [status] is an optional exit code to indicate success (0) or failure (any non-zero value).

3. Uses

o To end a shell session or script.

o To set an exit status for checking in other commands or scripts.

4. Example

o exit 0

o This command ends the session with an exit status of 0, indicating success.

Diploma Helper. Feel free to DM us at. 8698079745


❖ UNIT 03. PROCESS MANAGEMENT (22516)

❖ Winter 2019
1. Draw process state diagram. (2marks)
2. Write syntax of following commands: (2marks)
(i) Sleep
(ii) Kill
3. With neat diagram explain inter process communication model (4marks)
4. Explain ‘PS’ command with any four options. (4marks)
5. Write Unix command for following: (4marks)
(i) Create a folder OSY
(ii) Create a file FIRST in OSY folder
(iii) List / display all files and directories.
(iv) Write command to clear the screen
6. State and describe types of schedulers. (4marks)
7. Explain PCB with diagram. (4marks)
8. Explain multithreading model in detail. (6marks)

❖ Summer 2022
1. Draw a neat labelled diagram for process state. (2marks)
2. Give commands to perform following tasks:
(i) To add delay in script
(ii) To terminate a process (2marks)
3. Differentiate between shared memory system and message passing system of interprocess
communication. (4marks)
4. Describe use of ps and wait commands with suitable example. (4marks)
5. With suitable diagram, describe use of scheduling queues in process scheduling. (4marks)
6. Describe one-to-one multithreading model with suitable diagram. Also write any two advantages
of one-to-one model over many-to-one model. (6marks)

Diploma Helper. Feel free to DM us at. 8698079745


❖ UNIT 03. PROCESS MANAGEMENT (22516)

❖ Winter 2022
1. Define: Process, PCB. (2marks)
2. Write syntax of following commands: (2marks)
(i) Sleep
(ii) Kill
3. Explain shared memory model of Interprocess communication (IPC). (4marks)
4. Draw and explain process state diagram. (4marks)
5. Compare between Long term and short-term scheduler. (Any four points) (4marks)
6. Writer the outputs of following commands (6marks)
(i) Wait 2385018
(ii) Sleep 09
(iii) PS –u Asha

❖ Summer 2023
1. Draw and explain process control block in detail. (4marks)
2. Explain different types of schedulers. (4marks)
3. Draw process state diagram and describe each state. (4marks)
4. Explain the working of interprocess communication considering (6marks)
(i) Shared memory
(ii) Message passing

Diploma Helper. Feel free to DM us at. 8698079745


❖ UNIT 03. PROCESS MANAGEMENT (22516)

❖ Winter 2023
1. Draw neat labelled process state diagram along with the correct directions of arrows.
(2marks)
2. What is the use of PS command? Write long forms of UID, PID in the output of this
command. (2marks)
3. Explain shared memory method of IPC using neat labelled diagram. (4marks)
4. Explain following commands with their syntax (4marks)
i) Kill
ii) Sleep
iii) Wait
iv) Exit
5. Explain working of CPU switch from process to process with neat labelled diagram (4marks)
6. Differentiate between process and thread (any two points). Also discuss the benefits of
multithreaded programming (6marks)

❖ Summer 2024
1. Draw process state diagram. (2marks)
2. Write syntax of PWD command and explain its use with the help of suitable example. List any
four file operations. (2marks)
3. Describe message passing system of interprocess communication (IPC). (4marks)
4. Define Process. Draw a Process Control Block and explain the information in PCB. (4marks)
5. Describe how context switch is executed by operating system (4marks)
6. Explain user level thread and Kernel level thread with its advantages and disadvantages
(6marks)

Diploma Helper. Feel free to DM us at. 8698079745

You might also like