Unit I
Unit I
Operating System
Operating System lies in the category of system software. It basically
manages all the resources of the computer. An operating system acts as an
interface between the software and different parts of the computer or the
computer hardware. The operating system is designed in such a way that it
can manage the overall resources and operations of the computer. It is a
fully integrated set of specialized programs that handle all the operations of
the computer. It controls and monitors the execution of all other programs
that reside in the computer, which also includes application programs and
other system software of the computer. Examples of the operating system
are Windows, Linux, Mac OS, etc.
Objectives:
Let us now see some of the objectives of the operating system, which are:
© 2021– www.geekshelp.online
1. User Friendly: To make the computer system more interactive with a
more convenient interface for the users.
2. To provide easy access to users for using resources by acting as an
intermediary between the hardware and its users.
3. For managing the resources of a computer.
4. Controls and Monitoring: By keeping the track of who is using which
resource, granting resource requests, and mediating conflicting
requests from different programs and users.
5. Providing efficient and fair sharing of resources between the users and
programs.
Characteristics:
Let us now discuss some of the important characteristic features of
operating systems:
© 2021– www.geekshelp.online
Processor Management: It allocates the processor to a process and
then de-allocates the processor when it is no longer required or the job
is done.
Control on System Performance: It records the delays between the
request for a service and from the system.
Security: It prevents unauthorized access to programs and data by
means of passwords or some kind of protection technique.
Types of the operating system:
Batch Operating System: This type of operating system does not
interact with the computer directly. There is an operator which takes
similar jobs having the same requirements and groups them into
batches.
Time-sharing operating System: This type of operating system allows
many users to share computer resources. (Max utilization of the
resources).
Distributed operating System: This type of operating system manages
a group of different computers and makes appear to be a single
computer.
Network operating system: This type of operating system running on a
server and provides the capability to manage data, users, groups,
security, applications, and other networking functions.
Real-time operating system: This type of operating system serves real
time system and the time interval required to process and respond to
inputs is very small.
© 2021– www.geekshelp.online
Operating System Services
The operating system provides the programming environment in which a
programmer works on a computer system. The user program requests various
resources through the operating system. The operating system gives several
services to utility programmers and users. Applications access these services
through application programming interfaces or system calls. By invoking
those interfaces, the application can request a service from the operating
system, pass parameters, and acquire the operation outcomes.
o Program execution
o Control Input/output devices
o Program creation
o Error Detection and Response
o Accounting
o Security and Protection
o File Management
o Communication
Program execution
© 2021– www.geekshelp.online
Control Input/output devices
As there are numerous types of I/O devices within the computer system, and
each I/O device calls for its own precise set of instructions for the operation.
The Operating System hides that info with the aid of presenting a uniform
interface. Thus, it is convenient for programmers to access such devices
easily.
Program Creation
The Operating system offers the structures and tools, including editors and
debuggers, to help the programmer create, modify, and debugging programs.
An Error in a device may also cause malfunctioning of the entire device. These
include hardware and software errors such as device failure, memory error,
division by zero, attempts to access forbidden memory locations, etc. To avoid
error, the operating system monitors the system for detecting errors and
takes suitable action with at least impact on running applications.
While working with computers, errors may occur quite often. Errors may occur in the:
© 2021– www.geekshelp.online
To handle these errors and other types of possible errors, the operating
system takes appropriate action and generates messages to ensure correct
and consistent computing.
Accounting
Operating device affords safety to the statistics and packages of a person and
protects any interference from unauthorized users. The safety feature
counters threats, which are published via way of individuals out of doors the
manage of the running device.
For Example:
When a user downloads something from the internet, that program may
contain malicious code that may harm the already existing programs. The
operating system ensures that proper checks are applied while downloading
such programs.
If one computer system is shared amongst a couple of users, then the various
processes must be protected from another intrusion. For this, the operating
system provides various mechanisms that allow only those processes to use
resources that have gained proper authorization from the operating system.
The mechanism may include providing unique users ids and passwords to
each user.
© 2021– www.geekshelp.online
File management
For file management, the operating system must know the types of different
files and the characteristics of different storage devices. It has to offer the
proportion and safety mechanism of documents additionally.
Communication
The operating system manages the exchange of data and programs among
different computers connected over a network. This communication is
accomplished using message passing and shared memory.
System Calls
A system call is a method for a computer program to request a service from
the kernel of the operating system on which it is running. A system call is a
method of interacting with the operating system via programs. A system call
is a request from computer software to an operating system's kernel.
© 2021– www.geekshelp.online
Need of system calls in Operating System
There are various situations where you must require system calls in the
operating system. Following of the situations are as follows:
1. Process Control
2. File Management
3. Device Management
4. Information Maintenance
5. Communication
© 2021– www.geekshelp.online
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
Communication
© 2021– www.geekshelp.online
System Programs in Operating System
System Programming can be defined as the act of building Systems
Software using System Programming Languages. According to Computer
Hierarchy, one which comes at last is Hardware. Then it is Operating System,
System Programs, and finally Application Programs. Program Development
and Execution can be done conveniently in System Programs. Some of the
System Programs are simply user interfaces, others are complex. It
traditionally lies between the user interface and system calls.
So here, the user can only view up-to-the System Programs he can’t see
System Calls.
System Programs can be divided into these categories:
1. File Management:
A file is a collection of specific information stored in the memory of a
computer system. File management is defined as the process of
manipulating files in the computer system, its management includes the
process of creating, modifying and deleting files.
It helps to create new files in the computer system and placing them at
specific locations.
© 2021– www.geekshelp.online
It helps in easily and quickly locating these files in the computer
system.
It makes the process of sharing files among different users very easy
and user-friendly.
It helps to store files in separate folders known as directories.
These directories help users to search files quickly or to manage files
according to their types of uses.
It helps users to modify the data of files or to modify the name of files
in directories.
2. Status Information:
Information like date, time amount of available memory, or disk space is
asked by some users. Others providing detailed performance, logging, and
debugging information which is more complex. All this information is
formatted and displayed on output devices or printed. Terminal or other
output devices or files or a window of GUI is used for showing the output
of programs.
3. File Modification:
For modifying the contents of files we use this. For Files stored on disks
or other storage devices, we used different types of editors. For
searching contents of files or perform transformations of files we use
special commands.
4. Programming-Language support:
For common programming languages, we use Compilers, Assemblers,
Debuggers, and interpreters which are already provided to users. It
provides all support to users. We can run any programming language. All
languages of importance are already provided.
© 2021– www.geekshelp.online
5. Program Loading and Execution:
When the program is ready after Assembling and compilation, it must be
loaded into memory for execution. A loader is part of an operating system
that is responsible for loading programs and libraries. It is one of the
essential stages for starting a program. Loaders, relocatable loaders,
linkage editors, and Overlay loaders are provided by the system.
6. Communications:
Virtual connections among processes, users, and computer systems are
provided by programs. Users can send messages to another user on their
screen, User can send e-mail, browsing on web pages, remote login, the
transformation of files from one user to another.
© 2021– www.geekshelp.online
Process in Operating System
A process is a program in execution which then forms the basis of all
computation. The process is not as same as program code but a lot more than
it. A process is an 'active' entity as opposed to the program which is
considered to be a 'passive' entity. Attributes held by the process include
hardware state, memory, CPU, etc.
© 2021– www.geekshelp.online
The different Process States
In general, a process can have one of the following five states at a time.
© 2021– www.geekshelp.online
S.N. State & Description
1 Start
2 Ready
3 Running
4 Waiting
Process moves into the waiting state if it needs to wait for a resource,
such as waiting for user input, or waiting for a file to become available.
5 Terminated or Exit
© 2021– www.geekshelp.online
Operations on Processes
Process: 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.
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:
© 2021– www.geekshelp.online
1. Creation:
This the initial step of process execution activity. Process creation means the
construction of a new process for the execution. This might be performed by
system, user or old process itself. There are several events that leads to the
process creation. Some of the such events are following:
When we start the computer, system creates several background
processes.
A user may request to create a new process.
A process can create a new process itself while executing.
Batch system takes initiation of a batch job.
2. Scheduling/Dispatching:
The event or activity in which the state of the process is changed from ready
to running. It means the operating system puts the process from ready state
into the running state. Dispatching is done by 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 running state
© 2021– www.geekshelp.online
is preempted and process in ready state is dispatched by the operating
system.
3. Blocking:
When a process invokes an input-output system call that blocks the process
and operating system put in block mode. Block mode is basically a mode
where process waits for input-output. Hence on the demand of process
itself, operating system blocks the process and dispatches another process
to the processor. Hence, in process blocking operation, the operating system
puts the process in ‘waiting’ state.
4. Preemption:
When a timeout occurs that means the process hadn’t been terminated in
the allotted time interval and 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 ‘ready’ state.
5. 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 termination. Some of them are:
Process completes its execution fully and it indicates to the OS that it has
finished.
Operating system itself terminates the process due to service errors.
There may be problem in hardware that terminates the process.
One process can be terminated by another process.
© 2021– www.geekshelp.online
Inter Process Communication
In general, Inter Process Communication is a type of mechanism usually
provided by the operating system (or OS). The main aim or goal of this
mechanism is to provide communications in between several processes. In
short, the intercommunication allows a process letting another process know
that some event has occurred.
Definition
© 2021– www.geekshelp.online
Role of Synchronization in Inter Process Communication
These are the following methods that used to provide the synchronization:
1. Mutual Exclusion
2. Semaphore
3. Barrier
4. Spinlock
Mutual Exclusion:
It is generally required that only one process thread can enter the critical
section at a time. This also helps in synchronization and creates a stable state
to avoid the race condition.
Semaphore:
Semaphore is a type of variable that usually controls the access to the shared
resources by several processes. Semaphore is further divided into two types
which are as follows:
1. Binary Semaphore
2. Counting Semaphore
© 2021– www.geekshelp.online
Barrier:
A barrier typically not allows an individual process to proceed unless all the
processes does not reach it. It is used by many parallel languages, and
collective routines impose barriers.
Spinlock:
Spinlock is a type of lock as its name implies. The processes are trying to
acquire the spinlock waits or stays in a loop while checking that the lock is
available or not. It is known as busy waiting because even though the process
active, the process does not perform any functional operation (or task).
© 2021– www.geekshelp.online
These are a few different approaches for Inter- Process Communication:
1. Pipes
2. Shared Memory
3. Message Queue
4. Direct Communication
5. Indirect communication
6. Message Passing
7. FIFO
Pipe
The pipe is a type of data channel that is unidirectional in nature. It means that
the data in this type of data channel can be moved in only a single direction at
a time. Still, one can use two-channel of this type, so that he can able to send
and receive data in two processes. Typically, it uses the standard methods for
input and output. These pipes are used in all types of POSIX systems and in
different versions of window operating systems as well.
Shared Memory
Message Queue
© 2021– www.geekshelp.online
In general, several different messages are allowed to read and write the data
to the message queue. In the message queue, the messages are stored or stay
in the queue unless their recipients retrieve them. In short, we can also say
that the message queue is very helpful in inter-process communication and
used by all operating systems.
Message Passing
o send (message)
o received (message)
© 2021– www.geekshelp.online
Note: The size of the message can be fixed or variable.
Direct Communication
Indirect Communication
FIFO
© 2021– www.geekshelp.online
o File:
A file is a type of data record or a document stored on the disk and can be
acquired on demand by the file server. Another most important thing is
that several processes can access that file as required or needed.
o Signal:
As its name implies, they are a type of signal used in inter process
communication in a minimal way. Typically, they are the massages of
systems that are sent by one process to another. Therefore, they are not
used for sending data but for remote commands between multiple
processes.
Usually, they are not used to send the data but to remote commands in
between several processes.
© 2021– www.geekshelp.online
CPU Scheduling Criteria
Different CPU scheduling algorithms have different properties and the
choice of a particular algorithm depends on the various factors. Many
criteria have been suggested for comparing CPU scheduling algorithms.
The criteria include the following:
1. CPU Utilization:
The main objective of any CPU scheduling algorithm is to keep the CPU as
busy as possible. Theoretically, CPU utilization can range from 0 to 100 but in
a real-time system, it varies from 40 to 90 percent depending on the load
upon the system.
2. Throughput:
A measure of the work done by CPU is the number of processes being
executed and completed per unit time. This is called throughput. The
throughput may vary depending upon the length or duration of processes.
3. Turnaround Time:
For a particular process, an important criteria is how long it takes to execute
that process. The time elapsed from the time of submission of a process to
the time of completion is known as the turnaround time. Turn-around time is
the sum of times spent waiting to get into memory, waiting in ready queue,
executing in CPU, and waiting for I/O.
4. Waiting Time:
A scheduling algorithm does not affect the time required to complete the
process once it starts execution. It only affects the waiting time of a process
i.e. time spent by a process waiting in the ready queue.
5. Response time:
In an interactive system, turn-around time is not the best criteria. A process
may produce some output fairly early and continue computing new results
© 2021– www.geekshelp.online
while previous results are being output to the user. Thus another criteria is
the time taken from submission of the process of request until the first
response is produced. This measure is called response time.
© 2021– www.geekshelp.online
Types of CPU Scheduling
Here are two kinds of Scheduling methods:
Preemptive Scheduling
In Preemptive Scheduling, the tasks are mostly assigned with their priorities.
Sometimes it is important to run a task with a higher priority before another
lower priority task, even if the lower priority task is still running. The lower
priority task holds for some time and resumes when the higher priority task
finishes its execution.
Non-Preemptive Scheduling
In this type of scheduling method, the CPU has been allocated to a specific
process. The process that keeps the CPU busy will release the CPU either by
switching context or terminating. It is the only method that can be used for
various hardware platforms. That’s because it doesn’t need special hardware
(for example, a timer) like preemptive scheduling.
© 2021– www.geekshelp.online
3. Specific process switches from the waiting state to the ready state.
4. Process finished its execution and terminated.
© 2021– www.geekshelp.online
Maximize:
CPU utilization: CPU utilization is the main task in which the operating system
needs to make sure that CPU remains as busy as possible. It can range from 0
to 100 percent. However, for the RTOS, it can be range from 40 percent for
low-level and 90 percent for the high-level system.
Throughput: The number of processes that finish their execution per unit
time is known Throughput. So, when the CPU is busy executing the process, at
that time, work is being done, and the work completed per unit time is called
Throughput.
Minimize:
Waiting time: Waiting time is an amount that specific process needs to wait in
the ready queue.
© 2021– www.geekshelp.online
Turnaround Time: Turnaround time is an amount of time to execute a
specific process. It is the calculation of the total time spent waiting to get into
the memory, waiting in the queue and, executing on the CPU. The period
between the time of process submission to the completion time is the
turnaround time.
Interval Timer
Timer interruption is a method that is closely related to preemption. When a
certain process gets the CPU allocation, a timer may be set to a specified
interval. Both timer interruption and preemption force a process to return the
CPU before its CPU burst is complete.
What is Dispatcher?
It is a module that provides control of the CPU to the process. The Dispatcher
should be fast so that it can run on every context switch. Dispatch latency is
the amount of time needed by the CPU scheduler to stop one process and
start another.
Context Switching
Switching to user mode
Moving to the correct location in the newly loaded program.
© 2021– www.geekshelp.online
Types of CPU scheduling Algorithm
There are mainly six types of process scheduling algorithms
Scheduling Algorithms
© 2021– www.geekshelp.online
As the process enters the ready queue, its PCB (Process Control Block) is
linked with the tail of the queue. So, when CPU becomes free, it should be
assigned to the process at the beginning of the queue.
© 2021– www.geekshelp.online
Priority Based Scheduling
Priority scheduling is a method of scheduling processes based on priority. In
this method, the scheduler selects the tasks to work as per the priority.
Round-Robin Scheduling
Round robin is the oldest, simplest scheduling algorithm. The name of this
algorithm comes from the round-robin principle, where each person gets an
equal share of something in turn. It is mostly used for scheduling algorithms in
multitasking. This algorithm method helps for starvation free execution of
processes.
© 2021– www.geekshelp.online
significantly reduces the average waiting time for other processes awaiting
execution.
© 2021– www.geekshelp.online
The Purpose of a Scheduling algorithm
Here are the reasons for using a scheduling algorithm:
© 2021– www.geekshelp.online