Unit03 Osy (22516)
Unit03 Osy (22516)
❖ Process
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
o A process state represents the current status of a process during its execution.
3. Diagram Explanation
▪ 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.
▪ Terminated: The process has finished all its tasks and is now complete.
4. Real-Life Example
5. Advantages
6. Disadvantages
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.
3. Diagram Explanation
o Process State: Current status of the process (e.g., Ready, Running, Waiting).
o Accounting Info: Tracks resources used, time taken, and more for process control.
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
6. Disadvantages
o Slows down system performance if there are too many PCBs to manage.
❖ Scheduling Queue
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.
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.
4. Real-Life Example
▪ 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
6. Disadvantages
❖ Schedulers
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.
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.
4. Real-Life Example
▪ 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.
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.
6. Disadvantages
❖ Context Switch
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).
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.
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
6. Disadvantages
o Context switching adds overhead to the CPU, as saving and loading states takes time.
1. Introduction
o IPC refers to the methods used by processes to communicate and synchronize their
actions.
2. Diagram of IPC
3. Diagram Explanation
▪ Shared Memory : Multiple processes access the same memory space to read
and write data.
o It is one of the fastest IPC methods since data does not need to be copied between
the memory of different processes.
3. Diagram Explanation
o Processes can read from and write to this shared area, enabling quick data exchange.
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
6. Disadvantages
o This method does not require shared memory, making it more flexible and easier to
manage in some scenarios.
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.
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 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 Requires proper handling of message order and reliability to ensure all messages are
received.
❖ Threads
o They share the same memory space but can execute independently, improving
efficiency.
2. Diagram of Threads
Fig.(i) Threads
3. Diagram Explanation
o Threads: Each thread can execute different parts of the program simultaneously
while sharing resources like memory.
◆ 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.
o Threads can be scheduled on multiple CPUs or cores, allowing better CPU utilization
and faster execution.
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
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 Portability across different operating systems since they rely on user-level libraries.
3. Disadvantages
o If one thread blocks, all threads within the same process may also block.
◆ Kernel Threads
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.
3. Disadvantages
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.
❖ Multithreading Models
o Multithreading models define how threads are mapped to processes and how they
interact with the operating system.
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.
◆ 1. One-to-One Model
o In the One-to-One model, each user thread is mapped to a unique kernel thread.
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 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 Limited by the maximum number of threads the operating system can handle.
◆ 2. Many-to-One Model
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.
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 The operating system cannot perform kernel-level scheduling for user threads.
◆ 3. Many-to-Many Model
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 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 Overhead associated with managing multiple kernel threads and user threads.
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
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 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.
◆ 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
4. Example
o sleep 5s
◆ 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 [signal] is the type of termination (like -9 for forceful kill), and PID is the process ID.
3. Uses
4. Example
o kill -9 1234
o This command forcefully terminates the process with PID 1234.
◆ 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
4. Example
o exit 0
o This command ends the session with an exit status of 0, indicating success.
❖ 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)
❖ 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
❖ 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)