0% found this document useful (0 votes)
17 views

What Is CPU Scheduling?

Uploaded by

www.pnark
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

What Is CPU Scheduling?

Uploaded by

www.pnark
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

OS

1. What is CPU Scheduling?

CPU Scheduling is the process of determining which processes in a computer system


should be executed by the CPU at any given time. When multiple processes are ready to
run, the CPU scheduler decides which one to execute next to optimize CPU utilization
and improve system performance. This is crucial in a multitasking environment where
many processes may be waiting for CPU time.

2. Round Robin in CPU Scheduling

Round Robin (RR) is one of the simplest and most widely used CPU scheduling
algorithms. In Round Robin scheduling:

 Each process is assigned a fixed time slice or quantum.


 The CPU scheduler goes through the list of ready processes, giving each one a
chance to run for a single time quantum.
 If a process completes within its quantum, it leaves the queue. If it doesn't, it
goes to the back of the queue.
 This continues in a cyclic order, ensuring that all processes get an equal share of
the CPU time.

Example:

 Suppose we have three processes A, B, and C with a time quantum of 3


milliseconds.
 The CPU will run process A for 3 milliseconds, then B for 3 milliseconds, and then
C for 3 milliseconds.
 If A, B, or C need more time, they will wait for their next turn.

3. What are Semaphores and its applications?

Semaphores are synchronization tools used to control access to a common resource in


a concurrent system, such as a multitasking operating system. They help prevent race
conditions, where multiple processes attempt to modify shared data simultaneously.

There are two types of semaphores:

 Binary Semaphore (Mutex): Can only have two values, 0 or 1. It's used for
mutual exclusion, ensuring that only one process accesses a resource at a time.
 Counting Semaphore: Can have any non-negative integer value. It's used to
manage access to a resource that has a limited number of instances.

Applications:

 Resource Sharing: Semaphores can be used to manage access to resources like


printers, files, or database connections.
 Process Synchronization: Ensuring that processes execute in the correct order.
For example, a semaphore can ensure that a consumer process doesn't consume
an item until a producer process has produced it.

4. What is Deadlock?

Deadlock is a situation in a multitasking environment where two or more processes are


unable to proceed because each is waiting for the other to release a resource. This
results in all the involved processes being stuck indefinitely.

5. What are the conditions of Deadlock?

Deadlock occurs when the following four conditions are met simultaneously:

1. Mutual Exclusion: At least one resource must be held in a non-shareable mode.


Only one process can use the resource at any time.
2. Hold and Wait: A process holding at least one resource is waiting to acquire
additional resources held by other processes.
3. No Preemption: Resources cannot be forcibly removed from the processes
holding them; they must be released voluntarily.
4. Circular Wait: There exists a set of processes {P1, P2, ..., Pn} such that P1 is
waiting for a resource held by P2, P2 is waiting for a resource held by P3, and so
on, with Pn waiting for a resource held by P1.

6. Real life scenarios where deadlock happens

Deadlock can happen in various real-life scenarios. Here are a few examples:

 Traffic Gridlock: At an intersection, cars from all directions enter the intersection
and block each other, resulting in no car being able to move.
 Dining Philosophers Problem: Philosophers sitting around a table with a fork
between each pair. Each philosopher needs two forks to eat but picks up one fork
at a time, potentially leading to a situation where each philosopher has one fork
and is waiting for the other, causing a deadlock.
 Resource Allocation in Offices: Multiple employees needing to use a printer
(resource A) and a scanner (resource B) might each hold one and wait for the
other, causing a standstill.
7. What is Virtual Memory?

Virtual Memory is a memory management technique that gives an application the


impression it has contiguous working memory, while in reality, it may be fragmented
and may extend to disk storage. The operating system manages virtual memory to
increase the available address space using both physical memory (RAM) and secondary
storage (hard drives or SSDs).

Key concepts:

 Paging: The process of dividing the virtual memory into fixed-size blocks called
pages, and physical memory into blocks called frames. Pages are mapped to
frames, allowing non-contiguous storage.
 Swapping: The process of moving pages between physical memory and disk
storage to manage space and ensure that the most frequently accessed data
stays in RAM for quicker access.

Benefits:

 Isolation: Each process has its own virtual address space, providing isolation and
protection.
 Efficient use of memory: Not all parts of a program need to be in physical
memory simultaneously, allowing more programs to run concurrently.
 Larger address space: Programs can use more memory than what is physically
available on the system.

You might also like