0% found this document useful (0 votes)
45 views7 pages

Process Scheduling in Operating Systems

Process scheduling involves removing the currently running process from the CPU and selecting another process to run based on a scheduling strategy. There are three types of schedulers: long-term/job schedulers control the degree of multiprocessing; short-term/CPU schedulers select processes from ready state to run on CPU; and medium-term schedulers suspend and resume processes and perform swapping between memory and disk. Threads are lightweight processes that run within a process and share resources like memory, but have their own program counter and stack. Threads improve throughput, utilization of multiprocessors, context switching speed, responsiveness, and communication compared to processes.
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)
45 views7 pages

Process Scheduling in Operating Systems

Process scheduling involves removing the currently running process from the CPU and selecting another process to run based on a scheduling strategy. There are three types of schedulers: long-term/job schedulers control the degree of multiprocessing; short-term/CPU schedulers select processes from ready state to run on CPU; and medium-term schedulers suspend and resume processes and perform swapping between memory and disk. Threads are lightweight processes that run within a process and share resources like memory, but have their own program counter and stack. Threads improve throughput, utilization of multiprocessors, context switching speed, responsiveness, and communication compared to processes.
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

Process Control Block

See the previous lecture

Process Schedulers in Operating System

Process scheduling is the activity of the process manager that handles the removal of the
running process from the CPU and the selection of another process on the basis of a
particular strategy.
Process scheduling is an essential part of a Multiprogramming operating system. Such
operating systems allow more than one process to be loaded into the executable memory
at a time and the loaded process shares the CPU using time multiplexing.
There are three types of process schedulers.

1. Long Term or job scheduler:

It brings the new process to the ‘Ready State’. It controls the Degree of Multi-
programming, i.e., the number of processes present in a ready state at any point
in time. It is important that the long-term scheduler make a careful selection of
both I/O and CPU-bound processes. I/O-bound tasks are which use much of their
time in input and output operations while CPU-bound processes are which spend
their time on the CPU. The job scheduler increases efficiency by maintaining a
balance between the two. They operate at a high level and are typically used in
batch-processing systems.

2. Short-term or CPU scheduler:

It is responsible for selecting one process from the ready state for scheduling it
on the running state. Note: Short-term scheduler only selects the process to
schedule it doesn’t load the process on running. Here is when all the scheduling
algorithms are used. The CPU scheduler is responsible for ensuring there is no
starvation owing to high burst time processes.

The dispatcher is responsible for loading the process selected by the Short-term
scheduler on the CPU (Ready to Running State) Context switching is done by the
dispatcher only. A dispatcher does the following:
1. Switching context.
2. Switching to user mode.
3. Jumping to the proper location in the newly loaded program.
3. Medium-term scheduler:

It is responsible for suspending and resuming the process. It mainly does swapping
(moving processes from main memory to disk and vice versa). Swapping may be
necessary to improve the process mix or because a change in memory requirements
has overcommitted available memory, requiring memory to be freed up. It is helpful
in maintaining a perfect balance between the I/O bound and the CPU bound. It
reduces the degree of multiprogramming.

• I/O schedulers: I/O schedulers are incharge of managing the execution of I/O
operations such as reading and writing to discs or networks. They can use various
algorithms to determine the order in which I/O operations are executed, such as
FCFS (First-Come, First-Served) or RR (Round Robin).

• Real-time schedulers: In real-time systems, real-time schedulers ensure that


critical tasks are completed within a specified time frame. They can prioritize and
schedule tasks using various algorithms such as EDF (Earliest Deadline First) or
RM (Rate Monotonic).

Threads in Operating System (OS)


A thread is a single sequential flow of execution of tasks of a process so it is also known as thread
of execution or thread of control. There is a way of thread execution inside the process of any
operating system. Apart from this, there can be more than one thread inside a process. Each thread
of the same process makes use of a separate program counter and a stack of activation records and
control blocks. Thread is often referred to as a lightweight process.

The process can be split down into so many threads. For example, in a browser, many tabs can be
viewed as threads. MS Word uses many threads - formatting text from one thread, processing input
from another thread, etc.
Need of Thread:
o It takes far less time to create a new thread in an existing process than to create a new process.
o Threads can share the common data, they do not need to use Inter- Process communication.
o Context switching is faster when working with threads.
o It takes less time to terminate a thread than a process.

Process vs Thread:
The primary difference is that threads within the same process run in a shared
memory space, while processes run in separate memory spaces. Threads are not
independent of one another like processes are, and as a result threads share with
other threads their code section, data section, and OS resources (like open files and
signals). But, like process, a thread has its own program counter (PC), register set,
and stack space.

Difference between Process and Thread


[Link] Process Thread

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


then it is known as a process. thread.

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

3. It needs more time for work and It needs less time for work and
conception. conception.

4. Context switching takes maximum time Here, context switching takes


here. minimum time.

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


communication. communication.

6. It takes more resources. It takes fewer resources.

7. It is a heavy-weight process. It is a lightweight process.

8. If one process is obstructed then it will If one thread is obstructed then it will
not affect the operation of another affect the execution of another
process. process.
Types of Threads
In the operating system, there are two types of threads.

1. Kernel level thread.


2. User-level thread.

User-level thread
The operating system does not recognize the user-level thread. User threads can be easily
implemented and it is implemented by the user. If a user performs a user-level thread blocking
operation, the whole process is blocked. The kernel level thread does not know nothing about the
user level thread. The kernel-level thread manages user-level threads as if they are single-threaded
processes? examples: Java thread, POSIX threads, etc.

Advantages of User-level threads

1. The user threads can be easily implemented than the kernel thread.
2. User-level threads can be applied to such types of operating systems that do not support threads at
the kernel-level.
3. It is faster and efficient.
4. Context switch time is shorter than the kernel-level threads.
5. It does not require modifications of the operating system.
6. User-level threads representation is very simple. The register, PC, stack, and mini thread control blocks
are stored in the address space of the user-level process.
7. It is simple to create, switch, and synchronize threads without the intervention of the process.
Disadvantages of User-level threads

1. User-level threads lack coordination between the thread and the kernel.
2. If a thread causes a page fault, the entire process is blocked.

Kernel level thread


The kernel thread recognizes the operating system. There is a thread control block and process
control block in the system for each thread and process in the kernel-level thread. The kernel-level
thread is implemented by the operating system. The kernel knows about all the threads and manages
them. The kernel-level thread offers a system call to create and manage the threads from user-space.
The implementation of kernel threads is more difficult than the user thread. Context switch time is
longer in the kernel thread. If a kernel thread performs a blocking operation, the Banky thread
execution can continue. Example: Window Solaris.

Advantages of Kernel-level threads

1. The kernel-level thread is fully aware of all threads.


2. The scheduler may decide to spend more CPU time in the process of threads being large numerical.
3. The kernel-level thread is good for those applications that block the frequency.

Disadvantages of Kernel-level threads


1. The kernel thread manages and schedules all threads.
2. The implementation of kernel threads is difficult than the user thread.
3. The kernel-level thread is slower than user-level threads.

Components of Threads
Any thread has the following components.

1. Program counter
2. Register set
3. Stack space

Benefits of Threads
o Enhanced throughput of the system: When the process is split into many threads, and each thread
is treated as a job, the number of jobs done in the unit time increases. That is why the throughput of
the system also increases.
o Effective Utilization of Multiprocessor system: When you have more than one thread in one
process, you can schedule more than one thread in more than one processor.
o Faster context switch: The context switching period between threads is less than the process context
switching. The process context switch means more overhead for the CPU.
o Responsiveness: When the process is split into several threads, and when a thread completes its
execution, that process can be responded to as soon as possible.
o Communication: Multiple-thread communication is simple because the threads share the same
address space, while in process, we adopt just a few exclusive communication strategies for
communication between two processes.
o Resource sharing: Resources can be shared between all threads within a process, such as code, data,
and files. Note: The stack and register cannot be shared between threads. There is a stack and register
for each thread.

Common questions

Powered by AI

Context switching, which involves saving the state of a running process or thread and loading the state of another, impacts performance due to the overhead it generates. This overhead slows down CPU efficiency since it takes time and resources to switch context . Context switching for threads is generally more efficient than for processes because threads share the same memory space and resources, requiring only a switch of register sets, program counters, and stacks . In contrast, process context switching requires switching of memory mapping and operating system resources, resulting in higher overhead . This efficiency in thread context switching enhances system responsiveness and throughput because less time is spent in the process of switching, allowing more CPU time for execution .

Multithreading in operating systems offers several advantages that enhance system performance. These include improved system throughput as dividing a process into multiple threads allows multiple jobs to be executed in parallel, maximizing CPU utilization . It also improves the responsiveness of applications by allowing other threads to continue execution if one is blocked or performing a lengthy operation, thus enhancing user experience . Moreover, multithreading is efficient in resource sharing because threads within the same process can share code, data, and files, reducing the overhead of communication between threads compared to interprocess communication . Additionally, the context switch time between threads is shorter than that of processes, leading to reduced overhead and better real-time task handling . These advantages collectively lead to superior real-time performance, effective use of multiprocessor architecture, and better resource utilization .

OS-managed kernel threads have a significant impact on system scheduling and resource allocation as they are fully recognized by the operating system, allowing for more strategic and efficient scheduling decisions based on the global state of all threads and processes . The operating system's scheduler can prioritize kernel threads for CPU time and I/O operations, optimizing performance and allowing other processes to continue execution even if one thread blocks . In contrast, user-level threads rely on user-defined scheduling, lacking the OS's integrated view of system resources or other running processes, which can result in less effective resource allocation and scheduling decisions . Kernel threads are typically utilized in systems requiring advanced features and resource management due to their ability to coordinate better with the operating system .

User-level thread implementations are more beneficial in scenarios where speed and low overhead are crucial, such as in applications where the system calls frequency is low, and blocking operations are minimal. These threads are advantageous in environments that do not support kernel-level threads since they do not require OS intervention for management, leading to faster thread creation, execution, and switching . Their simplicity and lack of kernel dependency allow for efficient memory resource usage and fast context switching . However, they may be limited by their inability to perform well when frequent blocking operations occur, as a blocking on a user-level thread can stall the entire process . Despite these limitations, applications focusing on computation speed and resource efficiency often benefit greatly from user-level thread implementation .

User-level threads are implemented by users and recognized by user applications rather than the operating system. They are simple to create, manage, and switch between, providing advantages like faster context switches and lower overhead since they do not require kernel intervention . Their simplicity also allows them to be implemented even in operating systems that do not support kernel threads . However, they lack synchronization with the kernel, which means if a user-level thread blocks, the entire process can be blocked . Kernel-level threads, recognized by the OS, offer robust management and scheduling, allowing other threads to continue if one is blocked . However, they involve higher overhead due to more complex context switching and require more resources, making their implementation more challenging . These differences imply that user-level threads are better in applications where speed is essential and system calls are infrequent, while kernel-level threads are suitable for applications that require frequent I/O operations or system calls where blocking is common .

The choice of scheduling algorithms in process scheduling depends on several factors, such as the nature of the tasks being executed (e.g., I/O-bound vs. CPU-bound), system load, and specific requirements of the system, such as response time and resource utilization . In real-time systems, the critical factor is whether tasks must be completed within a specified time frame; thus, algorithms like EDF (Earliest Deadline First) or RM (Rate Monotonic) are often chosen because they prioritize tasks that are time-sensitive, ensuring that critical tasks are completed on time . Other considerations include system complexity, required throughput, and potential for starvation of certain processes, which determine whether simpler algorithms like FCFS (First-Come, First-Served) or more complex ones like Round Robin or priority-based scheduling are appropriate .

The long-term scheduler, or job scheduler, plays a critical role in process management by determining which processes are loaded into the ready state from a pool of potential candidates. Its primary objective is to control the degree of multiprogramming by selecting a balanced mix of I/O-bound and CPU-bound processes, thereby increasing system efficiency . Unlike the long-term scheduler, the short-term scheduler focuses on selecting processes from the ready state to the running state based on scheduling algorithms, ensuring that high burst time processes don't suffer from starvation . The medium-term scheduler, on the other hand, is responsible for swapping processes in and out of the main memory to balance I/O and CPU-bound processes and maintain the multiprogramming level .

Kernel-level threads involve considerable implementation complexity due to the necessity of maintaining detailed knowledge and control over all threads by the operating system . This complexity includes managing a thread control block and process control block for each thread, requiring more resources and leading to longer context switch times . Despite these complexities, kernel-level threads are suitable for applications that demand thorough thread management, such as those that rely heavily on I/O operations or need to frequently block and resume execution, as the kernel can ensure other threads continue running even when one blocks . On the other hand, user-level threads lack this complexity, enabling easier and faster implementation suited to applications prioritizing speed and resource constraints, but at the expense of less robust management and scheduling flexibility .

User-level threads face challenges primarily due to their lack of coordination with the kernel, leading to issues such as inefficient scheduling and blocking problems. Since the operating system does not recognize user-level threads individually, it cannot schedule them accurately based on system-wide priorities or needs; rather, user-level threads rely on user-defined scheduling algorithms which might not account for global conditions . Without kernel intervention, if a user-level thread performs a blocking operation or encounters a page fault, it can cause the entire process to be blocked, leading to potential inefficiencies and reduced responsiveness in applications . These challenges can adversely impact system performance, particularly in environments where efficiency and real-time responsiveness are critical .

I/O-bound processes spend more time performing input/output operations than utilizing the CPU, while CPU-bound processes require more computation time, spending significant time using the CPU . To maximize system efficiency, the long-term scheduler manages the influx of new processes to maintain a balance between I/O-bound and CPU-bound tasks, ensuring that neither overwhelms the system resources . The CPU or short-term scheduler then allocates CPU time to ensure fair execution without starvation, often giving preference to processes based on their nature and system load . Finally, the medium-term scheduler may swap processes in and out of main memory to improve the process mix based on changes in resource requirements, thereby optimizing the overall performance and responsiveness of the system .

You might also like