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

UNIT 1os

An Operating System (OS) acts as an interface between users and computer hardware, managing essential tasks such as file, memory, and process management. Various types of operating systems exist, including Windows, Linux, MacOS, iOS, and Android, each serving different purposes and functionalities. The OS provides critical services like program execution, error detection, security, and resource allocation, ensuring efficient operation of computer systems.
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)
6 views29 pages

UNIT 1os

An Operating System (OS) acts as an interface between users and computer hardware, managing essential tasks such as file, memory, and process management. Various types of operating systems exist, including Windows, Linux, MacOS, iOS, and Android, each serving different purposes and functionalities. The OS provides critical services like program execution, error detection, security, and resource allocation, ensuring efficient operation of computer systems.
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/ 29

UNIT -1 INTRODUCTION

Concept of os :
An Operating System (OS) is an interface between a computer user and computer hardware.
An operating system is a software which performs all the basic tasks like file management,
memory management, process management, handling input and output, and controlling
peripheral devices such as disk drives and printers.
If we consider a Computer Hardware is body of the Computer System, then we can say an
Operating System is its soul which brings it alive ie. operational. We can never use a
Computer System if it does not have an Operating System installed on it.
EXAMPLES-
 Windows: This is one of the most popular and commercial operating systems
developed and marketed by Microsoft. It has different versions in the market like
Windows 8, Windows 10 etc and most of them are paid.
 Linux This is a Unix based and the most loved operating system first released on
September 17, 1991 by Linus Torvalds. Today, it has 30+ variants available like Fedora,
OpenSUSE, CentOS, UBuntu etc. Most of them are available free of charges though
you can have their enterprise versions by paying a nominal license fee.
 MacOS This is again a kind of Unix operating system developed and marketed by
Apple Inc. since 2001.
 iOS This is a mobile operating system created and developed by Apple Inc. exclusively
for its mobile devices like iPhone and iPad etc.
 Android This is a mobile Operating System based on a modified version of the Linux
kernel and other open source software, designed primarily for touchscreen mobile
devices such as smartphones and tablets.
FUNCTIONS
 Process Management
 I/O Device Management
 File Management
 Network Management
 Main Memory Management
 Secondary Storage Management
 Security Management
 Command Interpreter System
 Control over system performance
 Job Accounting
 Error Detection and Correction
 Coordination between other software and users

TYPES OF OS
Types of Operating Systems
Operating Systems can be categorized according to different criteria like whether an
operating system is for mobile devices (examples Android and iOS) or desktop (examples
Windows and Linux).
8 Main Operating System Types: Categorized by Purpose and Functionality
 Batch Operating System
 Multi-Programming Operating System
 Multi-Processing Operating System
 Multi-User Operating Systems
 Distributed Operating System
 Network Operating System
 Real-Time Operating System
 Mobile Operating Systems
1. Batch Operating System
Batch processing was quite popular in the 1970s. Similar types of jobs have been
batched together and completed on time using this method.

Now, more than one individual can have access to this Operating System, and they
can submit their jobs to the system for execution. The system places all of the jobs
in a queue, first come, first served, and then executes them one at a time. When all
of the jobs are completed, the users receive their respective outputs.
Advantages of Batch Operating System
 Multiple users can share the batch systems.
 The idle time for the batch system is very little.
 It is easy to manage large work repeatedly in batch systems.
Disadvantages of Batch Operating System
 CPU is not used efficiently. When the current process is doing IO, the CPU is free and
could be utilized by other processes waiting.
 The other jobs will have to wait for an unknown time if any job fails.
 In a batch operating system, average response time increases as all processes are
processed one by one.
Examples of Batch Operating Systems: Payroll Systems, Bank Statements, etc.
2 Multi-Programming Operating System
Multiprogramming Operating Systems can be simply illustrated as more than one program is
present in the main memory and any one of them can be kept in execution. This is used for
better utilization of resources.
Advantages of, Multi-Programming Operating System
 CPU is better utilized, and the overall performance of the system improves.
 It helps in reducing the response time.
Disadvantages:
 Potential for Long Waits:
k
Long-term jobs may experience longer wait times due to being switched out of the CPU
while other, shorter jobs are executed.
 Tracking and Management Complexity:
Managing multiple concurrently running processes can be complex, requiring careful
scheduling and memory management.
 Scheduling Implementation:
Implementing efficient CPU scheduling can be challenging.
 No Direct User Interaction:
There is no direct user interaction with the program while it is in the execution phase.
Example: Imagine a computer running a text editor, a web browser, and a music player
simultaneously. The multiprogramming OS can switch rapidly between these tasks, allowing
the user to work on the text editor, browse the web, and listen to music without noticing a
significant performance slowdown.
3. Multiprocessing Operating System
Multiprocessing helps in performing parallel computing. There are several processors in a
system, each of which can run multiple processes at the same time. The system’s throughput
will be significantly increased as a result of this.
Parallel computing is performed by multiprocessing. The presence of more than one
processor in the system allows it to run multiple processes at the same time, increasing the
system’s throughput. Read more on Multiprocessing Operating System here.
Advantages of a Multi-User Operating System
 It increases the throughput of the system as processes can be parallelized.
 As it has several processors, so, if one processor fails, we can proceed with another
processor.
Disadvantages:
 Increased complexity:
Multiprocessing operating systems are more complex than single-processor systems,
requiring specialized algorithms for process synchronization and load balancing. This
complexity can lead to increased development and maintenance costs.
 Resource contention:
When multiple processors access shared resources, there can be potential for resource
contention, where one processor's actions can negatively impact others.
 Debugging challenges:
Debugging multiprocessing systems can be more challenging than debugging single-
processor systems, as it requires identifying and resolving issues across multiple processors.
 Increased memory requirements:
Multiprocessing systems may require more memory than single-processor systems, as each
processor needs its own memory space.
4. Multitasking Operating System
The multitasking OS refers to a logical extension of the multiprogramming Operating System,
which allows users to run many programs at the same time. It enables a user to complete
multiple computer tasks at the same time.
Types of Multi-Tasking Operating System
1. Preemptive Multitasking Operating System

 In preemptive multitasking, the operating system can


interrupt a running process and allocate the CPU to
another process.
 Examples include Windows 95, WindowsNT, Linux and
UNIX-based operating systems.
Advantages:
 Efficient CPU utilization by running multiple tasks
concurrently.
 Better system responsiveness and user experience.
 Allows higher-priority processes to take precedence over
lower-priority ones.
Disadvantages:
 Context switching overhead, which can reduce
performance.
 Complexity in process synchronization and management.
 Can lead to starvation if lower-priority processes are
never allocated CPU time.
Non-Preemptive Multitasking Operating System
 In non-preemptive multitasking, also known as
cooperative multitasking, the OS does not
initiate context switching from one process to
another.
 Examples include older versions of Macintosh OS (8.0-
9.2.2) and Windows 3.x.
Advantages:

 Simpler to implement compared to preemptive


multitasking.
 Lower overhead from context switching.
 Processes have more control over their
execution.
Disadvantages:

 Less efficient CPU utilization due to lack of


automatic task switching.
 Risk of system unresponsiveness if a process
fails to yield control.
 Difficult to manage real-time task priorities.

6. Network Operating System


These systems run on a server and provide the
capability to manage data, users, groups,
security, applications, and other networking
functions. These types of operating systems
allow shared access to files, printers, security,
applications, and other networking functions
over a small private network. One more
important aspect of Network Operating
Systems is that all the users are well aware of
the underlying configuration, of all other users
within the network, their connections, etc., and
that’s why these computers are popularly
known a tightly coupled systems .
Advantages of Network Operating System
 Highly stable, centralized servers.
 Security concerns are handled through servers.
 New technologies and hardware upgrades are easily integrated into the system.
 Server access is possible remotely from different locations and types of systems.
Disadvantages of Network Operating System
 Servers are costly.
 The user has to depend on a central location for most
operations.
 Maintenance and updates are required regularly.
Examples of Network Operating Systems are Microsoft Windows Server 2003, Microsoft
Windows Server 2008, UNIX, Linux, Mac OS X, Novell NetWare, BSD, etc.
7. Real-Time Operating System
These types of OSs serve real-time systems. The time interval required to process and
respond to inputs is very small. This time interval is called response time. Real-time
systems are used when there are time requirements that are very strict like missile systems,
air traffic control systems, robots, etc.

k Advantages of RTOS
 Maximum Consumption: Maximum utilization of devices and systems, thus more
output from all the resources.
 Task Shifting: The time assigned for shifting tasks in these systems is very less. For
example, in older systems, it takes about 10 microseconds to shift from one task to
another, and in the latest systems, it takes 3 microseconds.
 Focus on Application: Focus on running applications and give less importance to
applications that are in the queue.
 Real-time operating system in the embedded system: Since the size of programs is
small, RTOS can also be used in embedded systems like in transport and others.
 Error-Free,: These types of systems are error-free.
 Memory Allocation: Memory allocation is best managed in these types of systems.
Disadvantages of RTOS
 Limited Tasks: Very few tasks run at the same time and their concentration is very
less on a few applications to avoid errors.
 Use heavy system resources: Sometimes the system resources are not so good and
they are expensive as well.
 Complex Algorithms: The algorithms are very complex and difficult for the designer
to write.
 Device driver and interrupt signals: It needs specific device drivers and interrupt
signals to respond earliest to interrupts.
 Thread Priority: It is not good to set thread priority, as these systems are much less
prone to switching tasks.
Examples of Real-Time Operating Systems are Scientific experiments, medical imaging
systems, industrial control systems, weapon systems, robots, air traffic control systems, etc.
8. Mobile Operating Systems
Mobile operating systems are designed specifically for mobile devices such as smartphones
and tablets. Examples of such operating systems are Android and iOS. These operating
systems manage the hardware and software resources of the device, providing a platform
for running applications and ensuring a seamless user experience.
Advantages of Mobile Operating Systems
User-Friendly Interfaces: Mobile operating systems are designed to be intuitive and easy to
use, making them accessible to a wide range of users.
Extensive App Ecosystems: The availability of a vast number of applications allows users to
customize their devices to meet their specific needs.
Connectivity Options: Mobile operating systems support multiple connectivity options,
enabling users to stay connected wherever they go.
Regular Updates: Mobile operating systems receive regular updates, including new features,
security patches, and performance improvements.
Disadvantages Mobile Operating Systems
Battery Life Constraints: Despite advancements in power management, battery life remains
a challenge for mobile devices, especially with heavy usage.
Security Risks: Mobile devices are susceptible to various security threats, such as malware
and phishing attacks, which can compromise user data.
Fragmentation: In the case of Android, the wide range of devices and customizations can
lead to fragmentation, making it difficult for developers to ensure compatibility across all
devices.
Limited Hardware Resources: Mobile devices have limited processing power, memory, and
storage compared to desktop computers, which can affect the performance of resource-
intensive applications.
Operating System Services
The operating system provides services to both the user and the programs running in the
system. The operating system itself is a program that provides an environment to run other
programs in the system. To the user, the operating system provides various services to run
multiple user processes in the system. Operating system services such as process
management, memory management, and resource allocation management are provided by
the operating system.

Program execution
 Control Input/output devices
 Program creation
 Error Detection and Response
 Accounting
 Security and Protection
 File Management
 Communication
 User Interface
 Resource allocation
 Command interpretation
 Program execution
 The operating system loads the program into the memory and takes care of the
memory allocation for the program. Program execution is one of the operating
system services which also ensures that the program that is started can also end its
execution either normally or forcefully.
 The program is first loaded into the RAM and then the CPU is being assigned for
program execution through various CPU scheduling algorithms provided by the
operating system.
 After the program execution, the operating system also takes care of
process synchronization, inter-process communication, and deadlock handling.
 Control Input/output devices
 The programs running in the system need input and output devices access for
performing the input/output operations. The access to the input and output devices
is given by the operating system to the program for I/O operations.
 I/O operations mean writing or reading operations performed over any file or any
input/output device.
 Program creation
 In order to create, modify and debug programs the operating system provides tools
like editors and debuggers to make the task of programmers easy.
 Error Detection and Response
 Handling and detecting error is one of the crucial operating system services which
ensures the smooth working of the system.
 The error can occur in the system in the following devices or programs -
 Network connection error, loose connection of I/O devices, and restricted network
calls are some of the error that occur in input/output devices.
 The program run by the user in the system can also cause errors such as accessing
illegal memory, undefifned operations such as division by zero, excess use of CPU by
a program etc.
 Accounting
 The operating system keeps track of all the data of performance parameters and
response time of the system in order to make it more robust. This data is used to
improve the performance of the operating system and minimize the response time of
the system.
 Security and Protection
 If a user downloads a program from the internet there are chances that the program
can contain malicious code which can affect other programs in the system. The
operating system takes care that such a program is checked for any malicious
code before downloading it to the system.
 File Management
 File management is one of the operating system services that handles the memory
management for the programs running in the system.
 The operating system knows the information of all the types of different files and
properties of different storage devices and ensures the proper management and
safety of the files stored in the secondary storage devices.
 Communication
 The processes running in the system need to communicate with each other and also
the computers or systems connected over a network need to exchange data with
each other over a secure network. Operating system uses message passing and
shared memory to keep communication effective and safe.
 User Interface
 The user interacts with the system either by command-line interface or Graphical
user interface.
 The command-line interface uses text commands entered by the user to interact with
the system. These commands can also be given using a terminal emulator, or remote
shell client.
 A graphical user interface is a more user-friendly way to interact with the system. The
GUI provides icons, widgets, texts, labels, and text navigation. The user can easily
interact with these icons and widgets with just a click of a mouse or keyboard.
 Resource allocation
 The processes running in the system require resources to complete their execution.
 The operating system uses CPU scheduling to allocate resources effectively among
the processes ensuring better utilization of the CPU.
 The resources used by the processes can be CPU cycles, primary memory storage, file
storage, and I/O devices.
 Command Interpretation
 The user interacts with the system through commands and the operating system
interprets these commands and inputs and provides appropriate outputs accordingly.
 If the interpreter is separate from the kernel then the user can modify the interpreter
and prevent any unauthorized access to the system.
 Conclusion
 In conclusion, the operating system provides a plethora of services that are essential
for the smooth and efficient functioning of a computer system.
 These services include program execution, input/output device control, program
creation, error detection and response, accounting, security and protection, file
management, communication, user interface, resource allocation, and command
interpretation.
 By providing these services, the operating system acts as a bridge between the user
and the hardware, making it possible for users to interact with the computer system
in a meaningful way.

SYSTEM CALLS
When the process is being run, if the process requires certain actions that need to be
carried out by Operating System, the process has to go call the function which can
interact with the kernel to complete the actions. This special type of function call is
known as System Calls in OS. System calls provide the interface so that the process
can communicate with the Operating System.
k
n our computer system, we have two modes available.
1. User Mode: In this mode, execution is done on behalf of the user.
2. Monitor/Kernel-Mode: In this mode, execution is done on behalf of OS.

k
3. So when the process is under execution process executes under user mode,
but when the process requires some OS resources to complete the task, the
process makes a system call.
4. System calls in OS are executed in kernel mode on a priority basis.
5. On completion of the system call, the control is passed to process in user
mode.
6. The process continues the execution in user mode.
Types of System Calls in OS
There are mainly 5 types of system calls available:
 Process Control
 File Management
 Device Management
 Information Maintenance
 Communication

K
1. Process Control: It handles the system calls for process creation, deletion, etc.
Examples of process control system calls are: Load, Execute, Abort, and Wait for
Signal events for process.
2. File Management: File manipulation events like Creating, Deleting, Reading
Writing etc are being classified under file management system calls.
3. Device Management: Device Management system calls are being used to request
the device, release the device, and logically attach and detach the device.
4. Information Maintenance: This type of system call is used to maintain the
information about the system like time and date.
5. Communications: In order to have interprocess communications like send or receive
the message, create or delete the communication connections, to transfer status
information etc. communication system calls are used.
Important System Calls Used in OS
1. wait(): There are scenarios where the current process needs to wait for another
process to complete the task. So to wait in this scenario, wait() system call is used.
2. fork(): This system call creates the copy of the process that has called it. The one
which has called fork is called the parent process and the newly created copy is
called the child process.
3. exec(): This system call is called when the running process wants to execute another
executable file. The process id remains the same while the other resources used by
the process are replaced by the newly created process.
4. kill(): Sometimes while working, we require to terminate a certain process. So kill
system call is called which sends the termination signal to the process.
5. exit(): When we are actually required to terminate the program, an exit system call is
used. The resources that are occupied by the process are released after invoking the
exit system call.

What is Virtual Machine


Virtual Machine abstracts the hardware of our personal computer such as CPU, disk drives,
memory, NIC (Network Interface Card), etc, into many different execution environments as
per our requirements.. For example, VirtualBox. When we run different processes on an
operating system, it creates an illusion that each process is running on a different
processor having its own virtual memory, with the help of CPU scheduling and virtual-
memory techniques.
How Does a Virtual Machine Work?
Virtualization is the method of creating a software-based, or “virtual” version of a
computer with good amounts of CPU, memory, and storage that are “borrowed” from a
physical host computer (such as your personal computer) and/or a remote server. The
working of the virtual machine is very simple just check the published article on
the Working of a Virtual Machine.
Types of Virtual Machine
There are two types of Virtual Machine
1.Process Virtual Machine
2.System Virtual Machine

 1. Process Virtual Machine: A process virtual machine is


defined as a type of virtual machine that allows only a
single process to run as an application on the host system
and provides a platform-independent environment. A
process VM gets created once the process is started and
gets destroyed when the process ends. Java Virtual Machine
(JVM) is an example of a process virtual machine that allows
any operating system to run java applications.
 2. System Virtual Machine: A system virtual machine is
defined as a type of virtual machine that is fully virtualized
to substitute a physical machine. The physical resources of
the host device are shared among the multiple virtual
machines. This process of virtualization depends upon a
hypervisor that runs on the top of the operating system.

Advantages of Virtual Machine


 There are no protection problems because each virtual machine is completely
isolated from all other virtual machines.
 Virtual machine can provide an instruction set architecture that differs from real
computers.
 Easy maintenance, availability and convenient recovery.
 Energy and cost savings.
 Easy backup and clone.
 Virtual Machine provide Flexibility and Customization.
Disadvantages of Virtual Machine
 When multiple virtual machines are simultaneously running on a host computer,
one virtual machine can be affected by other running virtual machines, depending
on the workload.
 Virtual machines are not as efficient as a real one when accessing the hardware.

What is a Process in an Operating System?


In an operating system, a process is an instance of a program in execution. It is a basic unit of
work that can be scheduled and executed by the operating system.
Components of a Process in OS
The components of a process are:
 Program code/Text: The instructions that the process will execute.
 Data: The data that the process will use during its execution.
 Stack: A data structure that is used to store temporary data, such as function
parameters and return addresses.
 Heap: A data structure that is used to store dynamically allocated memory.

 Process control block (PCB): A data structure that contains information


about the process, such as its state, priority, and memory usage.

Process Life Cycle


The process life cycle is the sequence of states that a process goes through during its
existence. The process life cycle can be divided into the following stages:
1. New: The process has been created but has not yet been scheduled for execution.
2. Ready: The process is ready to be executed.
3. Running: The process is currently being executed.
4. Waiting: The process is waiting for an event to occur, such as the completion of an
I/O operation.
5. Terminated: The process has finished executing.
In the new state, the process has been created but has not yet been allocated any resources.
The process is moved to the runnable state when it is scheduled for execution. The process
is moved to the running state when it is given the CPU. The process is moved to the blocked
state when it is waiting for an event to occur. The process is moved to the terminated state
when it has finished executing.
Process Control Block
An OS serves in the creation, scheduling and termination of processes. The OS consists
of Process Control Block (PCB) that helps control the functioning of processes. Every process
in OS has a PCB associated with it. A PCB keeps track of processes by storing information
about various things like their state, I/O status and CPU Scheduling.
Understanding the components of a PCB will help us get to know the process information
better. A PCB comprises of the following:
1. Process ID: An identifier that helps us in identifying and locating a process.
2. Process state: It identifies the state that the process is currently in. It could be a new
process, ready, running, waiting or terminated.
3. Program counter: It holds the address of the next instruction to be executed for the
process. It also stores a count of the number of instructions in the process.

4. CPU registers: The content of processor registers gets stored here when the
process is in running state. The different kinds of CPU registers are
accumulators, index and general-purpose registers, instruction register and
condition code register.
5. CPU scheduling information: A process needs to be scheduled for
execution. Based on this scheduling, it goes from ready to running. CPU
Scheduling information contains process priority (to determine which
process goes first), pointers for scheduling queues (to mark the order of
execution), and various other scheduling parameters.
6. Accounting and business information: Contains details like CPU
utilization, real-time used by the process, number of jobs or processes, etc.
7. Memory-management information: Contains value of base and limit
registers, details about page and segment tables. It depends on the memory
system of the OS in use.
8. I/O status information: Comprises I/O related information including list of
I/O devices allocated to the process, status, etc.
Process States
The following are the process states in an operating system:
1. New: When a program is started, the operating system creates a new process for it.
The process is then placed in the new state. In the new state, the process has been
created but has not yet been allocated any resources.
2. Runnable: When a process is in the runnable state, it is ready to be executed. The
operating system maintains a queue of runnable processes. The scheduler selects a
process from the queue and moves it to the running state.
3. Running: When a process is in the running state, it is currently being executed. The
process has been given the CPU and is executing its instructions.
4. Blocked: When a process is in the blocked state, it is waiting for an event to occur.
The event could be the completion of an I/O operation, the arrival of a signal, or the
availability of a resource. When the event occurs, the process is moved to the
runnable state.

5. Terminated: When a process has finished executing, it is moved to the


terminated state. The operating system then releases all of the resources that
were allocated to the process.
What is Context Switching in OS?
Context switching in OS is the process of storing the state of a running
process or thread, so that it can be restored and resume execution at a later
point, and then loading the context or state of another process or thread and
run it.
Context switching is a fundamental concept in operating systems, and is
necessary for multitasking and efficient resource management. In a
multitasking operating system, multiple processes or threads can be running
concurrently. The operating system uses context switching to switch
between these processes or threads, so that each one can have a fair share of
the CPU's time.
Context switching in OS involves saving and restoring the following
information:
 The contents of the CPU's registers, which store the current state of the
process or thread.
 The process or thread's memory map, which maps the process or thread's
virtual memory addresses to physical memory addresses.
 The process or thread's stack, which stores the function call stack and other
information needed to resume execution.

6. State Diagram of Context Switching

Steps Of Context Switching in OS


The steps involved in context switching in OS are as follows:
1. Save the state of the current process: This includes saving the contents of the CPU
registers, the memory map, and the stack.
2. Load the state of the new process: This includes loading the contents of the CPU
registers, the memory map, and the stack.
3. Update the process scheduler: The process scheduler needs to be updated to reflect
the new state of the system.
4. Switch to the new process. This involves transferring control to the new process's
instruction pointer.

5. What is Thread in Operating System?

Thread is a sequential flow of tasks within a process. Threads in an operating


system can be of the same or different types. Threads are used to increase the
performance of the applications.
Each thread has its own program counter, stack, and set of registers.
However, the threads of a single process might share the same code and
data/file. Threads are also termed lightweight processes as they share
common resources.
Eg: While playing a movie on a device the audio and video are controlled
by different threads in the background.

Components of Thread
A thread has the following three components:
1. Program Counter
2. Register Set
3. Stack space
 Stack Space: Stores local variables, function calls, and return addresses specific to
the thread.
 Register Set: Hold temporary data and intermediate results for the thread’s
execution.
 Program Counter: Tracks the current instruction being executed by the thread.

Types of Thread
1. User Level Thread:
User-level threads are implemented and managed by the user and the kernel is not aware of
it.
 User-level threads are implemented using user-level libraries and the OS does not
recognize these threads.
 User-level thread is faster to create and manage compared to kernel-level thread.
 Context switching in user-level threads is faster.
 If one user-level thread performs a blocking operation then the entire process gets
blocked. Eg: POSIX threads, Java threads, etc.
2. Kernel level Thread:
Kernel level threads are implemented and managed by the OS.
 Kernel level threads are implemented using system calls and Kernel level threads
are recognized by the OS.
 Kernel-level threads are slower to create and manage compared to user-level
threads.
 Context switching in a kernel-level thread is slower.
 Even if one kernel-level thread performs a blocking operation, it does not affect other
threads. Eg: Window Solaris.
Advantages of Threading
 Threads improve the overall performance of a program.
 Threads increases the responsiveness of the program
 Context Switching time in threads is faster.
 Threads share the same memory and resources within a process.
 Communication is faster in threads.
 Threads provide concurrency within a process.
 Enhanced throughput of the system.
 Since different threads can run parallelly, threading enables the utilization of the
multiprocessor architecture to a greater extent and increases efficiency.
Key characteristics of threads:
 Lightweight:
Threads are generally considered lighter than processes, meaning they require fewer
resources to create and manage.
 Concurrent execution:
Multiple threads within the same process can execute concurrently, allowing for parallel
processing and improved performance.
 Shared resources:
Threads within the same process share the same memory space, allowing them to
communicate and access data easily.
 Independent execution:
Each thread has its own program counter, stack, and other execution-related resources,
allowing it to execute independently.
 Scheduling:
Threads are scheduled by the operating system to execute on the CPU.
Thread States in Operating Systems
(1) Ready
(2) Running
(3) Waiting
(4) Delayed
(5) Blocked

1. When an application is to be processed, then it creates a thread.

2. It is then allocated the required resources(such as a network) and it comes in


the READY queue.
3. When the thread scheduler (like a process scheduler) assign the thread with
processor, it comes in RUNNING queue.
4. When the process needs some other event to be triggered, which is outsides it’s
control (like another process to be completed), it transitions
from RUNNING to WAITING queue.
5. When the application has the capability to delay the processing of the thread, it
when needed can delay the thread and put it to sleep for a specific amount of time.
The thread then transitions from RUNNING to DELAYED queue.
An example of delaying of thread is snoozing of an alarm. After it rings for the first time and
is not switched off by the user, it rings again after a specific amount of time. During that
time, the thread is put to sleep.
6. When thread generates an I/O request and cannot move further till it’s done, it
transitions from RUNNING to BLOCKED queue.
7. After the process is completed, the thread transitions from RUNNING to FINISHED.

You might also like