Os Unit 1
Os Unit 1
Chapter-1:OS
We need a system which can act as an intermediary and manage all the processes and resources present
in the system.
An Operating System can be defined as an interface between user and hardware. It is responsible for
the execution of all the processes, Resource Allocation, CPU management, File Management and many
other tasks.
The purpose of an operating system is to provide an environment in which a user can execute programs
in convenient and efficient manner.
In Batch operating system, access is given to more than one person; they submit their respective jobs to
the system for the execution.
The system put all of the jobs in a queue on the basis of first come first serve and then executes the jobs
one by one. The users collect their respective output when all the jobs get executed.
The purpose of this operating system was mainly to transfer control from one job to another as soon as
the job was completed. It contained a small set of programs called the resident monitor that always
resided in one part of the main memory. The remaining part is used for servicing jobs.
Advantages of Batch OS
o The use of a resident monitor improves computer efficiency as it eliminates CPU time between
two jobs.
Disadvantages of Batch OS
1. Starvation
For Example:
There are five jobs J1, J2, J3, J4, and J5, present in the batch. If the execution time of J1 is very high, then
the other four jobs will never be executed, or they will have to wait for a very long time. Hence the other
processes get starved.
2. Not Interactive
Batch Processing is not suitable for jobs that are dependent on the user's input. If a job requires the input
of two numbers from the console, then it will never get it in the batch processing scenario since the user
is not present at the time of execution.
In a multiprogramming environment, when a process does its I/O, The CPU can start the execution of
other processes. Therefore, multiprogramming improves the efficiency of the system.
Advantages of Multiprogramming OS
o Throughout the system, it increased as the CPU always had one program to execute.
o Response time can also be reduced.
Disadvantages of Multiprogramming OS
o Multiprogramming systems provide an environment in which various systems resources are used
efficiently, but they do not provide any user interaction with the computer system.
SMP (symmetric multiprocessing) is computer processing done by multiple processors that share a
common operating system (OS) and memory. In symmetric multiprocessing, the processors share the
same input/output (I/O) bus or data path.
Asymmetric Multiprocessing :
Asymmetric Multiprocessing system is a multiprocessor computer system where not all of the multiple
interconnected central processing units (CPUs) are treated equally. In asymmetric multiprocessing, only a
master processor runs the tasks of the operating system.
o Increased reliability: Due to the multiprocessing system, processing tasks can be distributed
among several processors. This increases reliability as if one processor fails, the task can be given
to another processor for completion.
o Increased throughout: As several processors increase, more work can be done in less.
o Multiprocessing operating system is more complex and sophisticated as it takes care of multiple
CPUs simultaneously.
Multitasking Operating System
Preemptive multitasking is a task used by the OS to decide for how long a task should be executed before
allowing another task to use the OS.
Cooperative multitasking :
Cooperative multitasking is a type of computer multitasking in which the operating system never initiates
a context switch from a running process to another process.
o The multiple processors are busier at the same time to complete any task in a multitasking
environment, so the CPU generates more heat.
Network Operating System
An Operating system, which includes software and associated protocols to communicate with other
computers via a network conveniently and cost-effectively, is called Network Operating System.
Peer-to-peer network operating systems:
Peer-to-peer network operating systems allow users to share resources and files located on their
computers and to access shared resources found on other computers
Client/Server communication involves two components, namely a client and a server. They are usually
multiple clients in communication with a single server. The clients send requests to the server and the
server responds to the client requests.
o In this type of operating system, network traffic reduces due to the division between clients and
the server.
o This type of system is less expensive to set up and maintain.
o In this type of operating system, the failure of any node in a system affects the whole system.
o Security and performance are important issues. So trained network administrators are required for
network administration.
Real Time Operating System
In Real-Time Systems, each job carries a certain deadline within which the job is supposed to be
completed, otherwise, the huge loss will be there, or even if the result is produced, it will be completely
useless.
The Application of a Real-Time system exists in the case of military applications, if you want to drop a
missile, then the missile is supposed to be dropped with a certain precision.
Hard Real Time operating system :
In this, the time constraint is very short and strict. Even seconds of delay is not acceptable. Therefore, it is
compulsory to complete the task within the given time only.
Soft Real time RTOS, accepts some delays by the Operating system. In this type of RTOS, there is a
deadline assigned for a specific job, but a delay for a small amount of time is acceptable. So, deadlines are
handled softly by this type of RTOS.
These type of RTOS also need to follow the deadlines. However, missing a deadline may not have big
impact but could cause undesired affects, like a huge reduction in quality of a product.
o Easy to layout, develop and execute real-time applications under the real-time operating system.
o In a Real-time operating system, the maximum utilization of devices and systems.
A time-sharing operating system allows many users to be served simultaneously, so sophisticated CPU
scheduling schemes and Input/output management are required.
o The time-sharing operating system provides effective utilization and sharing of resources.
o This system reduces CPU idle and response time.
The PC is a general-purpose, cost-effective computer that stands for the personal computer. It is When Ed
Roberts introduced the MITS Altair 8800, he coined the term PC. Alternatively, it is referred to as a single-
user computer and a desktop that is designed to be used by a single end-user. All PCs depend on the
microprocessor technology that makes it capable for PC makers to set the whole CPU (central processing
unit) on a single chip.
Generally, a PC contains a keyboard, mouse, monitor, and system unit. Most of the personal computers
have an Internet or a network connection, including ports for connecting peripheral devices like external
hard drives, scanners, printers, digital cameras, and more. Even if the term PC can refer to any personal
computer, including an Apple Macintosh computer, but it is commonly used in the computer industry to
describe an IBM or IBM-compatible computer.
Personal computers are used to create spreadsheets, write papers, play games, track our finances,
account, run databases, and many other tasks. Also, at home, it is widely used for playing PC games,
multimedia entertainment, accessing the Internet and more. If your PC is connected to the Internet, you
can use it for communicating with friends via instant messaging programs, browsing the Web, checking e-
mail, and downloading data or files. It is normal for a personal computer to create a network by
connecting more than one PC together, even though they are designed to use as single-user systems.
A personal computer can be a laptop computer, a microcomputer, a handheld PC, a desktop computer, or
a tablet PC. Additionally, without PCs, life can be difficult as it has become such an integral part of our
lives.
o Computer case
o Motherboard
o Power supply
o CD/DVD drives/writers
o Random-access memory (RAM)
o Hard disk(s)
o Numerous external devices, such as a keyboard, printer, visual display and pointing device
Computers were only affordable by large enterprises and universities and occupied whole rooms in
the mid-1960s and 1970s. Multiple users accessed these computers through the attached terminals. In
the early 1980s, the term PC become popular and build as the Man of the Year on Time Magazine's choice
of PC for 1982. Technology had advanced far enough by the late 1980s that a small computer owned by a
single individual and could be used to perform a specific task. IBM termed as the IBM PC, introduced its
first personal computer in 1981. It became more popular speedily in the market.
o Education: A personal computer can be used for education purposes at school or college, work
and home. In school, a personal computer can be used to make an attendance sheet for students.
Also, a teacher can use the personal computer to learn about subjects if he does not have
expertise in the subject in which he is going to discuss a classroom. It may be used to take quizzes
in the classroom and learn about other cultures with the help of software programs.
A personal computer can be used to learn new skills to improve your performance and new
processes in the workplace. At home, it can be used by students or others to learn subjects such
as math, spelling, and reading by using a software program on the computer.
o Entertainment: A personal computer is also used for entertainment. On the computer, you can
play games with other people through software programs, even though they are thousands of
miles away. Additionally, if anyone does not want to play a game with someone, it offers users
options to use single-player games on the personal computer as well.
It allows you to watch movies and television shows any time, but you are required to download
them. You can also watch the videos online by connecting your personal computer to the Internet
or a network. In this way, you can manage your schedule accordingly, rather than let the television
networks control it for you.
o Communication: A personal computer offers multiple options for communication with others. As
you can use your computer to make a call over the Internet, and do not need a separate
telephone. A personal computer is not only used for work but can also be used to share and
synchronize schedules for personal life as well. It can be used by employees to work with other
employees as a team on opposite work schedules with the help of sharing documents and leaving
notes about the project. Furthermore, it helps to reduce society's reliance on the phone by
communicating over e-mail and instant messaging on computers.
Communication is also possible between humans and machines as well as between humans over
a computer. For example, you can turn off your lights while you are outside your house. Also, you
can set your DVR to record a movie if it is connected to your computer via a wireless Internet
connection.
o Information: A personal computer helps people to have information constantly at their fingertips
by connecting the Internet. On the computer, a user can type a desirable website URL into the
search bar of the browser and visit this site in just a few seconds. There are several user-submitted
communities, books, and encyclopedias, available online that are designed to offer specific types
of information, such as walkthroughs, video game. Additionally, you can use offline play
education games or digital encyclopedia software.
o Physical Side Effects: The use of a computer frequently can lead to a variety of physical
problems like backaches, tight hamstrings, wrist soreness and tension headaches. Laptop users
have faced problems as they need to bend their back in order to appropriately view the screen. It
can also be harmful to people who use a computer all day, as they can prone to tight muscles,
strained eyes and carpal tunnel syndrome. Furthermore, with a personal computer, people are
required to sit all day that can be a reason for more thoughtful health conditions.
o Internet Addiction: A person who has a deep addiction to the Internet may include addiction to
online gaming, cyber-relationships, online gambling, etc. Internet addiction people may use the
Internet to avoid from loneliness, stress, or depression in their daily life and get anxiety when they
are offline. Although the use of the internet within a limit is healthy and normal, people who have
an addiction to the Internet always feel as must constantly be them on the Internet. This often
affects work and decrease school performance.
Parallel Operating System
Introduction
An Operating System is the software responsible for managing all the computer system's resources. It is
the intermediary between the hardware and the user. It provides an environment through which a user
can execute tasks. Also, to make the working of the system more efficient, parallel processing is done.
Parallel Operating Systems help speed up the processing time by dividing the task into multiple sub-tasks
or sub-processes. This way, numerous processors can deal with various tasks simultaneously.
It can be achieved using various processors in a single system or systems forming a cluster. Thus,
numerous operating systems reach faster processing speeds.
Also, such systems can be used when multiple applications are to be run simultaneously without
interfering with each other. Such systems can handle multiple loads at the same time.
A parallel operating system has many applications, such as database and mining, argument reality, various
engineering fields, graphics, etc.
Some examples of parallel operating systems are Microsoft Hyper-V, Oracle VM, Sun xVM Server, etc.
Working of a Parallel Operating System
The main task is broken down into smaller sub-tasks in a parallel operating system design. Then, each
sub-task is assigned to a different system for processing. This way, the task is completed quickly since
each instruction is further divided for various CPU components.
Usually, a single system transmits and processes instructions whenever a task is assigned to different
components for simultaneous processing. In a parallel operating system, various systems achieve the
same much quicker, and such a system can handle much more loads of work simultaneously.
Functions of Parallel Operating System
Let us see some main functions of a parallel operating system.
It has a multiprocessing environment for faster processing. At the same time, it implements security
measures among the processors.
A parallel operating system design can handle much more work than a single system. Also, resources
are shared effectively among different processors.
Processes that may thread with each other are focused on so that there is no interference between
simultaneous processes.
Types of Parallel Operating Systems
Mainly, parallel operating systems are categorized into two types:- type 1 and type 2. Let us study them
one by one.
type-1:- This system runs directly on metal and acts as a native hypervisor. Systems that share physical
hardware or virtual machines can be used in this type. The operating system does not provide any
Input/Output emulations. For example, VMware uses the type-1 parallel operating system design.
type-2:- This type is hosted on a hypervisor. But, it is executed when the hypervisor runs on
conventional operating systems like Windows, Linux, etc.
It can solve large and complex operating system problems. It achieves this by sharing resources
efficiently.
It can allocate much more memory space and resources to processors than a single system making it
faster.
Such systems are costly since numerous processors require many resources. Also, coolers are used,
which are expensive too.
System Calls in Operating System (OS)
A system call is a way for a user program to interface with the operating system. The program requests
several services, and the OS responds by invoking a series of system calls to satisfy the request. A system
call can be written in assembly language or a high-level language like C or Pascal. System calls are
predefined functions that the operating system may directly invoke if a high-level language is used.
The Application Program Interface (API) connects the operating system's functions to user programs. It
acts as a link between the operating system and a process, allowing user-level programs to request
operating system services. The kernel system can only be accessed using system calls. System calls are
required for any programs that use resources.
Below are some examples of how a system call varies from a user function.
1. A system call function may create and use kernel processes to execute the asynchronous
processing.
2. A system call has greater authority than a standard subroutine. A system call with kernel-mode
privilege executes in the kernel protection domain.
3. System calls are not permitted to use shared libraries or any symbols that are not present in the
kernel protection domain.
4. The code and data for system calls are stored in global kernel memory.
If the request is permitted, the kernel performs the requested action, like creating or deleting a file. As
input, the application receives the kernel's output. The application resumes the procedure after the input
is received. When the operation is finished, the kernel returns the results to the application and then
moves data from kernel space to user space in memory.
A simple system call may take few nanoseconds to provide the result, like retrieving the system date and
time. A more complicated system call, such as connecting to a network device, may take a few seconds.
Most operating systems launch a distinct kernel thread for each system call to avoid bottlenecks. Modern
operating systems are multi-threaded, which means they can handle various system calls at the same
time.
1. Process Control
2. File Management
3. Device Management
4. Information Maintenance
5. Communication
Now, you will learn about all the different types of system calls one-by-one.
Process Control
Process control is the system call that is used to direct the processes. Some process control examples
include creating, load, abort, end, execute, process, terminate the process, etc.
File Management
File management is a system call that is used to handle the files. Some file management examples include
creating files, delete files, open, close, read, write, etc.
Device Management
Device management is a system call that is used to deal with devices. Some examples of device
management include read, device, write, get device attributes, release device, etc.
Information Maintenance
Information maintenance is a system call that is used to maintain information. There are some examples
of information maintenance, including getting system data, set time or date, get time or date, set system
data, etc.
Communication
Communication is a system call that is used for communication. There are some examples of
communication, including create, delete communication connections, send, receive messages, etc.
Examples of Windows and Unix system calls
There are various examples of Windows and Unix system calls. These are as listed below in the table:
Process Management
The process management component in the list of components of operating system is a mechanism for
managing several processes that are running on the operating system at the same time. One or more
processes are linked with every operating software application program.
Process management ensures that processes run smoothly. It also makes use of the memory allotted to
them and turns them off as necessary.
The phrase 'Process Management' refers to a mechanism for managing several processes being executed
in the operating system simultaneously. When a software application program is running, it has processes
related to the software application program.
The various types of process management functions are:
Synchronization Process
Suspension and Resumption.
Communication Process
Process Creation and Deletion.
File Management
.
File management is one of the most visible services of an operating system. Computers can store
information in several different physical forms; magnetic tape, disk, and drum are the most common
forms.
A file is defined as a set of correlated information and it is defined by the creator of the file. Mostly files
represent data, source and object forms, and programs. Data files can be of any type like alphabetic,
numeric, and alphanumeric.
The operating system implements the abstract concept of the file by managing mass storage device, such
as types and disks. Also files are normally organized into directories to ease their use. These directories
may contain files and other directories and so on.
The operating system is responsible for the following activities in connection with file management:
Computer networks are administered and managed via the network management component in the list of
components of operating system. Performance management, fault analysis, network provisioning, and
service quality management are among its services.
Each processor in a distributed system has its local memory. It is a group of computers or processors
linked together by a communication network and communicate over communication links such as fiber
optics or telephone lines.
Network management, enables users to design routing and connection methods without connectivity or
security issues by connecting the network entirely or partially.
The following are the characteristics of network management:
It provides users with access to the network's numerous resources.
We have access to resources that are shared. These aid in speeding of computations while also
ensuring data availability and dependability.
With the use of distributed systems, we can access various computing resources that vary in size and
function, such as microprocessors, minicomputers, and various general-purpose computer systems.
Main Memory Management
Main memory is an extensive collection of storage or bytes with an address. The memory management
component, in components of operating, employs a series of reads or writes to specific memory
addresses.
Before executing a program, it must be mapped to absolute addresses and loaded into memory. Several
factors influence the choice of a memory management method.
However, it primarily depends on the system's hardware design. Hardware support is required for each
algorithm. Main memory provides quick storage that the CPU can access immediately. It is more
expensive, and so has a smaller storage capacity. However, a program must reside in the main memory to
get executed.
Secondary Storage Management
During execution, programs assist in accessing data present in the main memory. The main memory is
insufficient to retain all the data and programs indefinitely. As a result, secondary storage serves as a
backup for the main memory. Assemblers and compilers are saved on a disc until loaded into memory
and processed on the disc.
Following are the features of secondary-storage management as a vital component in a list of
components of operating system:
Allocates storage
Manages free space
Disk scheduling
I/O Device Management
The I/O management system, in the list of components of operating system, has the following functions:
It provides a buffer caching system.
It includes a general device driver code.
It contains drivers for specific hardware devices.
I/O allows us to know about a device's unique characteristics.
Security Management
The components of operating system must be protected against one another's ac tions. Verifying that
processes desiring to access files, memory, CPU, or other hardware resources have the proper permissions
from the operating system can be done in many ways.
Memory addressing hardware, for example, can be used to verify that a process can run within its own
address space. The time assures that no process retains CPU control without relinquishing it.
Finally, no process is permitted to perform its I/O to protect the integrity of the various peripheral
devices.
Command Interpreter System
The operating system's command interpreter is a critical component. It serves as the user's main interface
with the system.
Operating System Services
Operating system is a software that acts as an intermediary between the user and computer hardware. It is
a program with the help of which we are able to run various applications. It is the one program that is
running all the time. Every computer must have an operating system to smoothly execute other programs.
The OS coordinates the use of the hardware and application programs for various users. It provides a
platform for other application programs to work. The operating system is a set of special programs that
run on a computer system that allows it to work properly. It controls input-output devices, execution of
programs, managing files, etc.
1. Program execution
2. Input Output Operations
3. Communication between Process
4. File Management
5. Memory Management
6. Process Management
7. Security and Privacy
8. Resource Management
9. User Interface
10. Networking
11. Error handling
12. Time Management
Program Execution
It is the Operating System that manages how a program is going to be executed. It loads the program
into the memory after which it is executed. The order in which they are executed depends on the CPU
Scheduling Algorithms. A few are FCFS, SJF, etc. When the program is in execution, the Operating System
also handles deadlock i.e. no two processes come for execution at the same time. The Operating System is
responsible for the smooth execution of both user and system programs. The Operating System utilizes
various resources available for the efficient running of all types of functionalities.
Operating System manages the input-output operations and establishes communication between the
user and device drivers. Device drivers are software that is associated with hardware that is being
managed by the OS so that the sync between the devices works properly. It also provides access to input-
output devices to a program when needed.
Communication between Processes
The Operating system manages the communication between processes. Communication between
processes includes data transfer among them. If the processes are not on the same computer but
connected through a computer network, then also their communication is managed by the Operating
System itself.
File Management
The operating system helps in managing files also. If a program needs access to a file, it is the operating
system that grants access. These permissions include read-only, read-write, etc. It also provides a platform
for the user to create, and delete files. The Operating System is responsible for making decisions
regarding the storage of all types of data or files, i.e, floppy disk/hard disk/pen drive, etc. The Operating
System decides how the data should be manipulated and stored.
Memory Management
Let’s understand memory management by OS in simple way. Imagine a cricket team with limited number
of player . The team manager (OS) decide whether the upcoming player will be in playing 11 ,playing 15
or will not be included in team , based on his performance . In the same way, OS first check whether the
upcoming program fulfil all requirement to get memory space or not ,if all things good, it checks how
much memory space will be sufficient for program and then load the program into memory at certain
location. And thus , it prevents program from using unnecessary memory.
Process Management
Let’s understand the process management in unique way. Imagine, our kitchen stove as the (CPU) where
all cooking(execution) is really happen and chef as the (OS) who uses kitchen-stove(CPU) to cook different
dishes(program). The chef(OS) has to cook different dishes(programs) so he ensure that any particular
dish(program) does not take long time(unnecessary time) and all dishes(programs) gets a chance to
cooked(execution) .The chef(OS) basically scheduled time for all dishes(programs) to run kitchen(all the
system) smoothly and thus cooked(execute) all the different dishes(programs) efficiently.
Security : OS keep our computer safe from an unauthorised user by adding security layer to it.
Basically, Security is nothing but just a layer of protection which protect computer from bad guys like
viruses and hackers. OS provide us defenses like firewalls and anti-virus software and ensure good
safety of computer and personal information.
Privacy : OS give us facility to keep our essential information hidden like having a lock on our door,
where only you can enter and other are not allowed . Basically , it respect our secrets and provide us
facility to keep it safe.
Resource Management
System resources are shared between various processes. It is the Operating system that manages resource
sharing. It also manages the CPU time among processes using CPU Scheduling Algorithms. It also helps in
the memory management of the system. It also controls input-output devices. The OS also ensures the
proper use of all the resources available by deciding which resource to be used by whom.
User Interface
User interface is essential and all operating systems provide it. Users either interface with the operating
system through the command-line interface or graphical user interface or GUI. The command interpreter
executes the next user-specified command.
A GUI offers the user a mouse-based window and menu system as an interface.
Networking
This service enables communication between devices on a network, such as connecting to the internet,
sending and receiving data packets, and managing network connections.
Error Handling
The Operating System also handles the error occurring in the CPU, in Input-Output devices, etc. It also
ensures that an error does not occur frequently and fixes the errors. It also prevents the process from
coming to a deadlock. It also looks for any type of error or bugs that can occur while any task. The well-
secured OS sometimes also acts as a countermeasure for preventing any sort of breach of the Computer
System from any external source and probably handling them.
Time Management
Imagine traffic light as (OS), which indicates all the cars(programs) whether it should be
stop(red)=>(simple queue) , start(yellow)=>(ready queue),move(green)=>(under execution) and this light
(control) changes after a certain interval of time at each side of the road(computer system) so that the
cars(program) from all side of road move smoothly without traffic.
Chapter-2 :Process
Long term scheduler is also known as job scheduler. It chooses the processes from the pool (secondary
memory) and keeps them in the ready queue maintained in the primary memory.
Long Term scheduler mainly controls the degree of Multiprogramming. The purpose of long term
scheduler is to choose a perfect mix of IO bound and CPU bound processes among the jobs present in
the pool.
If the job scheduler chooses more IO bound processes then all of the jobs may reside in the blocked state
all the time and the CPU will remain idle most of the time. This will reduce the degree of
Multiprogramming. Therefore, the Job of long term scheduler is very critical and may affect the system for
a very long time.
Short term scheduler is also known as CPU scheduler. It selects one of the Jobs from the ready queue and
dispatch to the CPU for the execution.
A scheduling algorithm is used to select which job is going to be dispatched for the execution. The Job of
the short term scheduler can be very critical in the sense that if it selects job whose CPU burst time is very
high then all the jobs after that, will have to wait in the ready queue for a very long time.
This problem is called starvation which may arise if the short term scheduler makes some mistakes while
selecting the job.
Medium term scheduler takes care of the swapped out processes.If the running state processes needs
some IO time for the completion then there is a need to change its state from running to waiting.
Medium term scheduler is used for this purpose. It removes the process from the running state to make
room for the other processes. Such processes are the swapped out processes and this procedure is called
swapping. The medium term scheduler is responsible for suspending and resuming the processes.
It reduces the degree of multiprogramming. The swapping is necessary to have a perfect mix of processes
in the ready queue.
Operations on Processes
A process is an activity of executing a program. Basically, it is a program under execution. Every
process needs certain resources to complete its task
Stack:
The process Stack contains the temporary data such as method/function parameters, return address and
local variables.
Heap:
This is dynamically allocated memory to a process during its run time
Data:
This section contains the global and static variables.
Text:
This includes the current activity represented by the value of Program Counter and the contents of the
processor's registers.
Operation on a Process:
The execution of a process is a complex activity. It involves various operations. Following are
the operations that are performed while execution of a process:
Creation :
This is the initial step of the process execution activity. Process creation means the construction
of a new process for execution. This might be performed by the system, the user, or the old
process itself. There are several events that lead to the process creation. Some of the such events
are the following:
1. When we start the computer, the system creates several background processes.
2. A user may request to create a new process.
3. A process can create a new process itself while executing.
4. The batch system takes initiation of a batch job.
Scheduling/Dispatching:
The event or activity in which the state of the process is changed from ready to run. It means the
operating system puts the process from the ready state into the running state. Dispatching is done
by the operating system when the resources are free or the process has higher priority than the
ongoing process. There are various other cases in which the process in the running state is
preempted and the process in the ready state is dispatched by the operating system.
Blocking:
When a process invokes an input-output system call that blocks the process, and operating
system is put in block mode. Block mode is basically a mode where the process waits for input-
output. Hence on the demand of the process itself, the operating system blocks the process and
dispatches another process to the processor. Hence, in process-blocking operations, the operating
system puts the process in a ‘waiting’ state.
Preemption:
When a timeout occurs that means the process hadn’t been terminated in the allotted time
interval and the next process is ready to execute, then the operating system preempts the process.
This operation is only valid where CPU scheduling supports preemption. Basically, this happens
in priority scheduling where on the incoming of high priority process the ongoing process is
preempted. Hence, in process preemption operation, the operating system puts the process in a
‘ready’ state.
Process Termination
Process termination is the activity of ending the process. In other words, process termination is
the relaxation of computer resources taken by the process for the execution. Like creation, in
termination also there may be several events that may lead to the process of termination. Some of
them are:
1. The process completes its execution fully and it indicates to the OS that it has finished.
2. The operating system itself terminates the process due to service errors.
3. There may be a problem in hardware that terminates the process.
4. One process can be terminated by another process.
Process Concept
A question that arises in discussing operating systems involves what to call all the CPU activities. A batch
system executes jobs, whereas a time-shared system has user programs, or tasks. Even on a single-user
system such as Microsoft Windows, a user may be able to run several programs at one time: a word
processor, a web browser, and an e-mail package. Even if the user can execute only one program at a
time, the operating system may need to support its own internal programmed activities, such as memory
management. In many respects, all these activities are similar, so we call all of them processes. The terms
job and process are used almost interchangeably in this text. Although we personally prefer the term
process, much of operating-system theory and terminology was developed during a time when the
major activity of operating systems was job processing. It would be misleading to avoid the use of
commonly accepted terms that include the word job (such as job scheduling) simply because process has
superseded job.
The Process
Informally, as mentioned earlier, a process is a program in execution. A process is more than the
program code, which is sometimes known as the text section. It also includes the current activity, as
represented by the value of the program counter and the contents of the processor's registers. A process
generally also includes the process stack, which contains temporary data (such as function parameters,
return addresses, and local variables), and a data section, which contains global variables.
A process may also include a heap, which is memory that is dynamically allocated during process run
time. We emphasize that a program by itself is not a process; a program is a passive entity, such as a file
containing a list of instructions stored on disk (often called an executable file), whereas a process is an
active entity, with a program counter specifying the next instruction to execute and a set of associated
resources. A program becomes a process when an executable file is loaded into memory. Two common
techniques for loading executable files are double-clicking an icon representing the executable file and
entering the name of the executable file on the command line (as in prog. exe or a. out.) Although two
processes may be associated with the same program, they are nevertheless considered two separate
execution sequences. For instance, several users may be running different copies of the mail program, or
the same user may invoke many copies of the web browser program. Each of these is a separate process;
and although the text sections are equivalent, the data, heap, and stack sections vary. It is also common
to have a process that spawns many processes as it runs.
Process State
As a process executes, it changes state. The state of a process is defined in part by the current activity of
that process. Each process may be in one of the following states:
• Waiting. The process is waiting for some event to occur (such as an I/O completion or reception of a
signal).
• Terminated.
The process has finished execution. These names are arbitrary, and they vary across operating systems.
The states that they represent are fotind on all systems, however. Certain operating systems also more
finely delineate process states. It is important to realize that only one process can be running on any
processor at any instant. Many processes may be ready and limiting, however..
Process Control Block
Each process is represented in the operating system by a process control block (PCB)—also called a task
control block. It contains many pieces of information associated with a specific process, including these: •
Process state. The state may be new, ready, running, waiting, halted, and so on.
• Program counter. The counter indicates the address of the next instruction to be executed for this
process.
• CPU registers. The registers vary in number and type, depending on the computer architecture. They
include accumulators, index registers, stack pointers, and general-purpose registers, plus any condition-
code information. Along with the program counter, this state information must be saved when an
interrupt occurs, to allow the process to be continued correctly afterward
• Memory-management information. This information may include such information as the value of the
base and limit registers, the page tables, or the segment tables, depending on the memory system used
by the operating system .
• Accounting information. This information includes the amount of CPU and real time used, time limits,
account members, job or process numbers, and so on.
• I/O status information. This information includes the list of I/O devices allocated to the process, a list
of open files, and so on. In brief, the PCB simply serves as the repository for any information that may
vary from process to process.
Cooperating Processes:
In an operating system, everything is around the process. How the process goes through several
different states. So in this article, we are going to discuss one type of process called as Cooperating
Process. In the operating system there are two types of processes:
Independent Process: Independent Processes are those processes whose task is not
dependent on any other processes.
Cooperating Process: Cooperating Processes are those processes that depend on other
processes or processes. They work together to achieve a common task in an operating system.
These processes interact with each other by sharing the resources such as CPU, memory, and I/O
devices to complete the task.
So now let’s discuss the concept of cooperating processes and how they are used in operating systems.
Inter-Process Communication (IPC): Cooperating processes interact with each other via
Inter-Process Communication (IPC). As they are interacting to each other and sharing some
resources with another so running task get the synchronization and possibilities of deadlock
decreases. To implement the IPC there are many options such as pipes, message queues,
semaphores, and shared memory.
Concurrent execution: These cooperating processes executes simultaneously which can be
done by operating system scheduler which helps to select the process from ready queue to go to
the running state. Because of concurrent execution of several processes the comple tion time
decreases.
Resource sharing: In order to do the work, cooperating processes cooperate by sharing
resources including CPU, memory, and I/O hardware. If several processes are sharing resources as if
they have their turn, synchronization increases as well as the response time of process increase.
Deadlocks: As cooperating processes shares their resources, there might be a deadlock
condition. Deadlock means if p1 process holds the resource A and wait for B and p2 process hold
the B and wait for A. In this condition deadlock occur in cooperating process. To avoid deadlocks,
operating systems typically use algorithms such as the Banker’s algorithm to manage and allocate
resources to processes.
Process scheduling: Cooperating processes runs simultaneously but after context switch, which
process should be next on CPU to executes, this is done by the scheduler. Scheduler do it by using
several scheduling algorithms such as Round-Robin, FCFS, SJF, Priority etc.
In conclusion, cooperating processes are essential unit to increase the concurrent execution and
because of it, the performance of the overall system increases.
Thread in Operating System
Within a program, a Thread is a separate execution path. It is a lightweight process that the operating
system can schedule and run concurrently with other threads. The operating system creates and manages
threads, and they share the same memory and resources as the program that created them. This enables
multiple threads to collaborate and work efficiently within a single program.
A thread is a single sequence stream within a process. Threads are also called lightweight processes as
they possess some of the properties of processes. Each thread belongs to exactly one process. In an
operating system that supports multithreading, the process can consist of many threads. But threads can
be effective only if CPU is more than 1 otherwise two threads have to context switch for that single CPU.
Threads run in parallel improving the application performance. Each such thread has its own CPU state
and stack, but they share the address space of the process and the environment.
Threads can share common data so they do not need to use interprocess communication. Like the
processes, threads also have states like ready, executing, blocked, etc.
Priority can be assigned to the threads just like the process, and the highest priority thread is
scheduled first.
Each thread has its own Thread Control Block (TCB). Like the process, a context switch occurs for the
thread, and register contents are saved in (TCB). As threads share the same address space and
resources, synchronization is also required for the various activities of the thread.
Why Multi-Threading?
A thread is also known as a lightweight process. The idea is to achieve parallelism by dividing a process
into multiple threads. For example, in a browser, multiple tabs can be different threads. MS Word uses
multiple threads: one thread to format the text, another thread to process inputs, etc. More advantages of
multithreading are discussed below.
Multithreading is a technique used in operating systems to improve the performance and responsiveness
of computer systems. Multithreading allows multiple threads (i.e., lightweight processes) to share the
same resources of a single process, such as the CPU, memory, and I/O devices.
For more, refer to Multithreading in OS.
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 a process, a thread has its own program counter (PC), register set, and
stack space.
Advantages of Thread
Responsiveness: If the process is divided into multiple threads, if one thread completes its execution,
then its output can be immediately returned.
Faster context switch: Context switch time between threads is lower compared to the process context
switch. Process context switching requires more overhead from the CPU.
Effective utilization of multiprocessor system: If we have multiple threads in a single process, then
we can schedule multiple threads on multiple processors. This will make process execution faster.
Resource sharing: Resources like code, data, and files can be shared among all threads within a
process. Note: Stacks and registers can’t be shared among the threads. Each thread has its own stack
and registers.
Communication: Communication between multiple threads is easier, as the threads share a common
address space. while in the process we have to follow some specific communication techniques for
communication between the two processes.
Enhanced throughput of the system: If a process is divided into multiple threads, and each thread
function is considered as one job, then the number of jobs completed per unit of time is increased,
thus increasing the throughput of the system.
Types of Threads
Threads are of two types. These are described below.
User Level Thread
Kernel Level Thread
User Level Thread is a type of thread that is not created using system calls. The kernel has no work in the
management of user-level threads. User-level threads can be easily implemented by the user. In case
when user-level threads are single-handed processes, kernel-level thread manages them. Let’s look at the
advantages and disadvantages of User-Level Thread.
A kernel Level Thread is a type of thread that can recognize the Operating system easily. Kernel Level
Threads has its own thread table where it keeps track of the system. The operating System Kernel helps in
managing threads. Kernel Threads have somehow longer context switching time. Kernel helps in the
management of threads.
Components of Threads