KEMBAR78
OS Unit 1 | PDF | Process (Computing) | Operating System
0% found this document useful (0 votes)
25 views21 pages

OS Unit 1

Uploaded by

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

OS Unit 1

Uploaded by

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

OPERATING SYSTEM

Unit 1: Definition of OS – OS structures: OS services – System calls – Virtual


machines – Process Management: Process concept – Process Scheduling – Operation
on Processes – Co-operating Processes – Inter-Process Communication

What is Operating System?

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.

Generally, a Computer System consists of the following components:

• Computer Users are the users who use the overall computer system.
• Application Softwares are the softwares which users use directly to perform
different activities. These softwares are simple and easy to use like Browsers,
Word, Excel, different Editors, Games etc. These are usually written in high -
level languages, such as Python, Java and C++.
• System Softwares are the softwares which are more complex in nature and
they are more near to computer hardware. These software are usually written
in low-level languages like assembly language and includes Operating
Systems (Microsoft Windows, macOS, and Linux), Compiler, and Assembler
etc.
• Computer Hardware includes Monitor, Keyboard, CPU, Disks, Memory, etc.

Operating System – Functions

• Process Management
• I/O Device Management
• File Management
• Network Management
• Main Memory Management
• Secondary Storage Management
• Security Management
• Job Accounting
• Error Detection and Correction

Types of 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. It is the responsibility of the operator to sort jobs with
similar needs. Batch Operating System is designed to manage and execute a large
number of jobs efficiently by processing them in groups.

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.

Multi-tasking/Time-sharing Operating systems


It is a type of Multiprogramming system with every process running in round
robin manner. Each task is given some time to execute so that all the tasks work
smoothly. Each user gets the time of the CPU as they use a single system. These
systems are also known as Multitasking Systems. The task can be from a single user
or different users. The time that each task gets to execute is called quantum. After
this time interval is over, the OS switches over to the next task.
Multi-Processing Operating System
A Multi-Processing Operating System is a type of Operating System in which
more than one CPU is used for the execution of resources. It betters the throughput
of the System.

Multi-User Operating Systems


These systems allow multiple users to be active at the same time. This system
can be either a multiprocessor or a single processor with interleaving.

Distributed Operating System


These types of operating systems are a recent advancement in the world of
computer technology and are being widely accepted all over the world and, that too,
at a great pace. Various autonomous interconnected computers communicate with
each other using a shared communication network. Independent systems possess
their own memory unit and CPU Systems. These systems' processors differ in size
and function. The major benefit of working with these types of operating systems is
that it is always possible that one user can access the files or software which are not
present on his system but on some other system connected within this network, i.e.,
remote access is enabled within the devices connected to that network.
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.

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.
Operating System Structures
Important terminologies

• Kernal − Kernal is the central component of an operating system architecture


in most of the implementation. A kernal is responsible for all major operations
and interaction with the hardware. A kernal manages memory, processor,
input/output devices and provides interface to application programs to
interact with hardware components.
• Shell − Shell is an interface of an operating system. It can be command line
interface or a graphical user interface. User interacts with an operating system
using shell. Application programs can also use shell interface to interact with
underlying operating system.
• System Softwares − System softwares are the programs which interact with
Kernal and provides interface for security managment, memory management
and other low level activities.
• Application Programs − Application softwares/Programs are the one using
which a user interacts with the operating system. For example a word processor
to create a document and save it on the file system, a notepad to create notes
etc.

Operating System Services

An Operating System provides services to both the users and to the programs.

• It provides programs an environment to execute.


• It provides users the services to execute the programs in a convenient manner.

Following are a few common services provided by an operating system −

• Program execution
• I/O operations
• File System manipulation
• Communication
• Error Detection
• Resource Allocation
• Protection

Program execution

Operating systems handle many kinds of activities from user programs to system
programs like printer spooler, name servers, file server, etc. Each of these activities is
encapsulated as a process.

A process includes the complete execution context (code to execute, data to


manipulate, registers, OS resources in use). Following are the major activities of an
operating system with respect to program management −
• Loads a program into memory.
• Executes the program.
• Handles program's execution.
• Provides a mechanism for process synchronization.
• Provides a mechanism for process communication.
• Provides a mechanism for deadlock handling.

I/O Operation

An I/O subsystem comprises of I/O devices and their corresponding driver


software. Drivers hide the peculiarities of specific hardware devices from the users.

An Operating System manages the communication between user and device drivers.

• I/O operation means read or write operation with any file or any specific I/O
device.
• Operating system provides the access to the required I/O device when
required.

File system manipulation

A file represents a collection of related information. Computers can store files


on the disk (secondary storage), for long-term storage purpose. Examples of storage
media include magnetic tape, magnetic disk and optical disk drives like CD, DVD.
Each of these media has its own properties like speed, capacity, data transfer rate and
data access methods.

A file system is normally organized into directories for easy navigation and usage.
These directories may contain files and other directions. Following are the major
activities of an operating system with respect to file management −

• Program needs to read a file or write a file.


• The operating system gives the permission to the program for operation on file.
• Permission varies from read-only, read-write, denied and so on.
• Operating System provides an interface to the user to create/delete files.
• Operating System provides an interface to the user to create/delete directories.
• Operating System provides an interface to create the backup of file system.

Communication

In case of distributed systems which are a collection of processors that do not


share memory, peripheral devices, or a clock, the operating system manages
communications between all the processes. Multiple processes communicate with one
another through communication lines in the network.
The OS handles routing and connection strategies, and the problems of contention
and security. Following are the major activities of an operating system with respect to
communication −

• Two processes often require data to be transferred between them


• Both the processes can be on one computer or on different computers, but are
connected through a computer network.
• Communication may be implemented by two methods, either by Shared
Memory or by Message Passing.

Error handling

Errors can occur anytime and anywhere. An error may occur in CPU, in I/O
devices or in the memory hardware. Following are the major activities of an operating
system with respect to error handling −

• The OS constantly checks for possible errors.


• The OS takes an appropriate action to ensure correct and consistent computing.

Resource Management

In case of multi-user or multi-tasking environment, resources such as main


memory, CPU cycles and files storage are to be allocated to each user or job. Following
are the major activities of an operating system with respect to resource management

• The OS manages all kinds of resources using schedulers.


• CPU scheduling algorithms are used for better utilization of CPU.

Protection

Considering a computer system having multiple users and concurrent


execution of multiple processes, the various processes must be protected from each
other's activities.

Protection refers to a mechanism or a way to control the access of programs,


processes, or users to the resources defined by a computer system. Following are the
major activities of an operating system with respect to protection −

• The OS ensures that all access to system resources is controlled.


• The OS ensures that external I/O devices are protected from invalid access
attempts.
• The OS provides authentication features for each user by means of passwords.

System Call
A system call is a programmatic way in which a computer program requests
a service from the kernel of the operating system on which it is executed. A system
call is a way for programs to interact with the operating system. A computer
program makes a system call when it requests the operating system's kernel. System
call provides the services of the operating system to the user programs via the
Application Program Interface(API). System calls are the only entry points into the
kernel system and are executed in kernel mode.

A figure representing the execution of the system call is given as follows −

As can be seen from this diagram, the processes execute normally in th e user mode
until a system call interrupts this. Then the system call is executed on a priority basis
in the kernel mode. After the execution of the system call, the control returns to the
user mode and execution of user processes can be resumed.
In general, system calls are required in the following situations –

• If a file system requires the creation or deletion of files. Reading and writing
from files also require a system call.
• Creation and management of new processes.
• Network connections also require system calls. This includes sending and
receiving packets.
• Access to a hardware devices such as a printer, scanner etc. requires a system
call.

Types of System Calls


There are mainly five types of system calls. These are explained in detail as foll ows
Process Control
These system calls deal with processes such as process creation, process
termination etc.
File Management
These system calls are responsible for file manipulation such as creating a file,
reading a file, writing into a file etc.
Device Management
These system calls are responsible for device manipulation such as reading
from device buffers, writing into device buffers etc.
Information Maintenance
These system calls handle information and its transfer between the operating
system and the user program.

Communication

These system calls are useful for inter process communication. They also deal
with creating and deleting a communication connection.

open()
The open() system call is used to provide access to a file in a file system. This system
call allocates resources to the file and provides a handle that the process uses to refer
to the file. A file can be opened by multiple processes at the same time or be restricted
to one process. It all depends on the file organisation and file system.
read()
The read() system call is used to access data from a file that is stored in the file system.
The file to read can be identified by its file descriptor and it should be opened using
open() before it can be read. In general, the read() system calls takes three arguments
i.e. the file descriptor, buffer which stores read data and number of bytes to be read
from the file.
write()
The write() system calls writes the data from a user buffer into a device such as a file.
This system call is one of the ways to output data from a program. In general, the write
system calls takes three arguments i.e. file descriptor, pointer to the buffer where data
is stored and number of bytes to write from the buffer.
close()
The close() system call is used to terminate access to a file system. Using this system
call means that the file is no longer required by the program and so the buffers are
flushed, the file metadata is updated and the file resources are de-allocated.

Virtual Machines (VMs)


Based on our needs, a virtual machine abstracts the hardware of our personal
computer, including the CPU, disc drives, RAM, and NIC (Network Interface Card),
into a variety of different execution contexts, giving us the impression that each
execution environment is a different computer. An illustration of it is a virtual box.
An operating system enables us to run multiple processes concurrently while
making it appear as though each one is using a different processor and virtual
memory by using CPU scheduling and virtual memory techniques.
The fundamental issue with the virtual machine technique is disc systems.
Let's say the physical machine only has three disc drives, but it needs to host seven
virtual machines. The program that creates virtual machines would need a
significant amount of disc space in order to provide virtual memory and spooling,
so it should be clear that it is impossible to assign a disc drive to every virtual
machine. The answer is to make virtual discs available.

Process

A process is basically a program in execution. The execution of a process must


progress in a sequential fashion.
To put it in simple terms, we write our computer programs in a text file and
when we execute this program, it becomes a process which performs all the tasks
mentioned in the program.

When a program is loaded into the memory and it becomes a process, it can
be divided into four sections stack, heap, text and data. The following image shows a
simplified layout of a process inside main memory

S.N. Component & Description

Stack
1 The process Stack contains the temporary data such as method/function
parameters, return address and local variables.

Heap
2
This is dynamically allocated memory to a process during its run time.

Text
3 This includes the current activity represented by the value of Program Counter and
the contents of the processor's registers.

Data
4
This section contains the global and static variables.

Process State
As a process executes, it changes state

• New State: The process is being created.


• Running State: A process is said to be running if it has the CPU, that is,
process actually using the CPU at that particular instant.
• Blocked (or waiting) State: A process is said to be blocked if it is waiting for
some event to happen such that as an I/O completion before it can proceed.
Note that a process is unable to run until some external event happens.
• Ready State: A process is said to be ready if it needs a CPU to execute. A
ready state process is runnable but temporarily stopped running to let
another process run.
• Terminated state: The process has finished execution.

What is the difference between process and program?


1) Both are same beast with different name or when this beast is sleeping (not
executing) it is called program and when it is executing becomes process.

2) Program is a static object whereas a process is a dynamic object.

3) A program resides in secondary storage whereas a process resides in main


memory.

4) The span time of a program is unlimited but the span time of a process is limited.
5) A process is an 'active' entity whereas a program is a 'passive' entity.

6) A program is an algorithm expressed in programming language whereas a


process is expressed in assembly language or machine language.

Diagram of Process State

Process Control Block (PCB):

• A Process Control Block is a data structure maintained by the Operating


System for every process.
• The PCB is identified by an integer process ID (PID).
• A PCB keeps all the information needed to keep track of a process as listed
below

S.N. Information & Description


1 Process State: The current state of the process i.e., whether it is ready,
running, waiting, or whatever.
2 Process privileges: This is required to allow/disallow access to system
resources.
3 Process ID: Unique identification for each of the process in the
operating system.
4 Pointer: A pointer to parent process.
5 Program Counter: Program Counter is a pointer to the address of the
next instruction to be executed for this process.
6 CPU registers: Various CPU registers where process need to be stored
for execution for running state.
7 CPU Scheduling Information: Process priority and other scheduling
information which is required to schedule the process.
8 Memory management information: This includes the information of
page table, memory limits, Segment table depending on memory used
by the operating system.
9 Accounting information: This includes the amount of CPU used for
process execution, time limits, execution ID etc.
10 IO status information: This includes a list of I/O devices allocated to
the process.

The architecture of a PCB is completely dependent on Operating System and


may contain different information in different operating systems. The PCB is
maintained for a process throughout its lifetime, and is deleted once the
process terminates.
Process Scheduling
Definition
• The process scheduling is the activity of the process manager that
handles the removal of the running process from the CPU and the
selection of another process on the basis of a particular strategy.
• Process scheduling is an essential part of a Multiprogramming operating
systems.
• Such operating systems allow more than one process to be loaded into
the executable memory at a time and the loaded process shares the CPU
using time multiplexing.

What are Scheduling Queues?

• All processes, upon entering into the system, are stored in the Job
Queue.
• Processes in the Ready state are placed in the Ready Queue.
• Processes waiting for a device to become available are placed in Device
Queues. There are unique device queues available for each I/O device.
A new process is initially put in the Ready queue. It waits in the ready queue until it
is selected for execution (or dispatched). Once the process is assigned to the CPU
and is executing, one of the following several events can occur:
• The process could issue an I/O request, and then be placed in the I/O
queue.
• The process could create a new sub-process and wait for its termination.
• The process could be removed forcibly from the CPU, as a result of an
interrupt, and be put back in the ready queue.

In the first two cases, the process eventually switches from the waiting state to the
ready state, and is then put back in the ready queue. A process continues this cycle
until it terminates, at which time it is removed from all queues and has its PCB and
resources deallocated.

Categories of Scheduling
Scheduling falls into one of two categories:
• Non-Preemptive: In this case, a process's resource cannot be taken before
the process has finished running. When a running process finishes and
transitions to a waiting state, resources are switched.
• Preemptive: In this case, the OS can switch a process from running state
to ready state. This switching happens because the CPU may give other
processes priority and substitute the currently active process for the
higher priority process.

Types of Process Schedulers


There are three types of process schedulers:
1. Long Term or Job Scheduler
Long Term Scheduler loads a process from disk to main memory for execution. The
new process to the 'Ready State'.
• It mainly moves processes from Job Queue to Ready Queue.
• It controls the Degree of Multi-programming, i.e., the number of
processes present in a ready state or in main memory at any point in
time.
• It is important that the long-term scheduler make a careful selection of
both I/O and CPU-bound processes. I/O-bound tasks are which use
much of their time in input and output operations while CPU-bound
processes are which spend their time on the CPU. The job scheduler
increases efficiency by maintaining a balance between the two.
• In some systems, the long-term scheduler might not even exist. For
example, in time-sharing systems like Microsoft Windows, there is
usually no long-term scheduler. Instead, every new process is directly
added to memory for the short-term scheduler to handle.
• Slowest among the three (that is why called long term).

2. Short-Term or CPU Scheduler


CPU Scheduler is responsible for selecting one process from the ready state for
running (or assigning CPU to it).
• STS (Short Term Scheduler) must select a new process for the CPU
frequently to avoid starvation.
• The CPU scheduler uses different scheduling algorithms to balance the
allocation of CPU time.
• It picks a process from ready queue.
• Its main objective is to make the best use of CPU.
• It mainly calls dispatcher.
• Fastest among the three (that is why called Short Term).

The dispatcher is responsible for loading the process selected by the Short-term
scheduler on the CPU (Ready to Running State). Context switching is done by the
dispatcher only. A dispatcher does the following work:
• Saving context (process control block) of previously running process if
not finished.
• Switching system mode to user mode.
• Jumping to the proper location in the newly loaded program.
Time taken by dispatcher is called dispatch latency or process context switch time.

3. Medium-Term Scheduler
Medium Term Scheduler (MTS) is responsible for moving a process from memory
to disk (or swapping).
• It reduces the degree of multiprogramming (Number of processes
present in main memory).
• A running process may become suspended if it makes an I/O request. A
suspended processes cannot make any progress towards completion. In
this condition, to remove the process from memory and make space for
other processes, the suspended process is moved to the secondary
storage. This process is called swapping, and the process is said to be
swapped out or rolled out. Swapping may be necessary to improve the
process mix (of CPU bound and IO bound)
• When needed, it brings process back into memory and pick up right
where it left off.
• It is faster than long term and slower than short term.

Context Switching
In order for a process execution to be continued from the same point at a later
time, context switching is a mechanism to store and restore the state or context of a
CPU in the Process Control block. A context switcher makes it possible for multiple
processes to share a single CPU using this method. A multitasking operating
system must include context switching among its features.
The state of the currently running process is saved into the process control
block when the scheduler switches the CPU from executing one process to another.
The state used to set the computer, registers, etc. for the process that will run next is
then loaded from its own PCB. After that, the second can start processing.

In order for a process execution to be continued from the same point at a later time,
context switching is a mechanism to store and restore the state or context of a CPU
in the Process Control block.
Operations on 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:

1. 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:
• When we start the computer, the system creates several background
processes.
• A user may request to create a new process.
• A process can create a new process itself while executing.
• The 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 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.
3. 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.
4. 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.
5. 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:
• The process completes its execution fully and it indicates to the OS that it
has finished.
• The operating system itself terminates the process due to service errors.
• There may be a problem in hardware that terminates the 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.

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 completion 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.

Inter Process Communication


Inter process communication (IPC) allows different processes running on a
computer to share information with each other. IPC allows processes to
communicate by using different techniques like sharing memory, sending messages
or using files. It ensures that processes can work together without interfering with
each other. Cooperating processes require an Inter Process Communication (IPC)
mechanism that will allow them to exchange data and information.
The two fundamental models of Inter Process Communication are:
• Shared Memory
• Message Passing
An operating system can implement both methods of communication. First,
we will discuss the shared memory methods of communication and then message
passing. Communication between processes using shared memory requires
processes to share some variable and it completely depends on how the programmer
will implement it. Suppose process 1 and process 2 are executing simultaneously
and they share some resources or use some information from another process.
Process1 generates information about certain computations or resources being used
and keeps it as a record in shared memory. When process 2 needs to use the shared
information, it will check in the record stored in shared memory and take note of the
information generated by process 1 and act accordingly. Processes can use shared
memory for extracting information as a record from another process as well as for
delivering any specific information to other processes.

Shared Memory
• Shared memory is the memory that can be simultaneously accessed by
multiple processes.
• This is done so that the processes can communicate with each other.
• All POSIX systems, as well as Windows operating systems use shared
memory.

Message Queue
• Multiple processes can read and write data to the message queue without
being connected to each other.
• Messages are stored in the queue until their recipient retrieves them.
• Message queues are quite useful for inter-process communication and are
used by most operating systems.
• If two processes p1 and p2 want to communicate with each other, they
proceed as follow:
• Establish a communication link (if a link already exists, no need to establish
it again.)
• Start exchanging messages using basic primitives.
• We need at least two primitives: send(message, destination) or
send(message) receive(message, host) or receive(message)

Why is Inter-Process Communication Necessary?

Inter-process communication is necessary in process management for a number of


reasons, such as −

1. Information sharing

Inter-process communication is used for instruction sharing and several tasks and
commands are performed in the computer by sharing the operating system to the
task. The information is needed to be shared so that a task is performed.

2. Achieving Modularity

When a large task is broken into smaller modules, each of these modules is executed
by one or more processes. As these processes are a part of a bigger task, they need to
coordinate among themselves, share data and control signals to achieve the task. IPC
helps in coordination among the processes and thus helps to achieve modularity.

3. Faster Processes

Properly synchronised inter-process communication helps processes to complete


tasks faster resulting in overall speedup of the system.
4. Convenience

Individual users may work on many tasks at the same time and users may edit,
listen to music and do all types of tasks at a time because the operating system is
very convenient due to inter-process communication.

You might also like