0% found this document useful (0 votes)
47 views27 pages

Chapter 2 Notessdfdsgds

The document discusses the key services and components of an operating system. It describes several core services provided by operating systems, including program execution, I/O operations, file system manipulation, communication, error detection, resource allocation, and protection. It then provides details on how operating systems handle program loading and execution, I/O operations, file management, communication between processes, error handling, resource management, and access protection. Finally, it discusses system calls as the interface between processes and the operating system kernel.

Uploaded by

Kiran janjal
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)
47 views27 pages

Chapter 2 Notessdfdsgds

The document discusses the key services and components of an operating system. It describes several core services provided by operating systems, including program execution, I/O operations, file system manipulation, communication, error detection, resource allocation, and protection. It then provides details on how operating systems handle program loading and execution, I/O operations, file management, communication between processes, error handling, resource management, and access protection. Finally, it discusses system calls as the interface between processes and the operating system kernel.

Uploaded by

Kiran janjal
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/ 27

Chapter 2:- Services and components of Operating System

❖ Services of Operating System


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
1
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 I ai.
• 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.
2
• 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.
3
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 in Operating System


The interface between a process and an operating system is provided by system calls. In general,
system calls are available as assembly language instructions. They are also included in the
manuals used by the assembly level programmers. System calls are usually made when a process
in user mode requires access to a resource. Then it requests the kernel to provide the resource via
a system call.
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 the user mode until a system
call interrupts this. Then the system call is executed on a priority basis in the kernel mode. After

4
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 follows −
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 interprocess communication. They also deal with creating and
deleting a communication connection.
Some of the examples of all the above types of system calls in Windows and Unix are given as
follows −

5
Types of System Calls Windows Linux

CreateProcess() fork()
Process Control ExitProcess() exit()
WaitForSingleObject() wait()

CreateFile() open()
ReadFile() read()
File Management WriteFile() write()
CloseHandle() close()
SetConsoleMode() ioctl()
Device Management ReadConsole() read()
WriteConsole() write()
GetCurrentProcessID() getpid()
Information Maintenance SetTimer() alarm()
Sleep() sleep()
CreatePipe() pipe()
Communication CreateFileMapping() shmget()
MapViewOfFile() mmap()

There are many different system calls as shown above. Details of some of those system calls are
as follows −
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()

6
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.
Operating System Component
An operating system provides the environment within which programs are internally,
operating systems vary greatly in their makeup, being organized along many different
lines. The design of a new operating system is a major task.

7
We can create a system as large and complex as an operating system only by
partitioning it into smaller pieces. Each piece should be a well-delineated portion of the
system, with carefully defined inputs, outputs, and functions. Obviously, not all systems
have the same structure. However, many modern systems share the goal of supporting
the system components.
The Operating System can be considered to be a collection of many such callable
programs or services categorized under following major heads viz.
1. Process Management
2. Main Memory Management
3. File Management
4. I/O System Management
5. Secondary Storage Management
6. Networking Protection System
7. Command Interpreter System

1) Process Management
A program does nothing unless its instructions are executed by a CPU. A process can be
thought of as a program in execution. Example of Process,
1. A time-shared user program such as a compiler is a process.
2. A word-processing program being run by an individual user on a PC is a process.
3. A system task, such as sending output to a printer, is also a process.
Hence we can consider a process to be a job or a time-shared program
The function of the Operating System in this regard is to keep track of all the
competing processes (we will call a running program, a process), schedule them (i.e.
sequence them), dispatch (i.e. run or execute) them one after the other, but while doing
so, try to give each user an impression that he has the full control of the CPU.
A process needs certain resources—including CPU time, memory, files, and I/O
devices—to accomplish its task. These resources are either given to the process when it
is created, or allocated to it while it is running. In addition to the various physical and
logical resources that a process obtains when it is created, various initialization data (or I
may be passed along. For example
Consider a process whose function is to display the status of a file on the screen of a
terminal. What will happen?
1. The process will be given as an input the name of the file,
2. Will execute the appropriate instructions and system calls to obtain display on
the terminal the desired information.
3. When the process terminates the operating system will reclaim any reusable 8
resources.
Program v ersus Process
A program by itself is not a process; a program is a passive entity such as the
contents of a file stored on disk, whereas a process is an active entity, with a program
counter specifying the next instruction to execute. The execution of a process must be
sequential. The CPU executes one instruction of the process after another, until the
process completes.

9
Further at any time at most one instruction is executed on behalf of the process.
Thus although two processes may be associated with the same program, they are
nevertheless considered two separate execution sequences. It is common to have
a program that spawns many processes as it runs.
A process is the unit of work in a system. Such a system consists of a collection
of processes, some of which are operating-system processes (those that execute
system code) and the rest of which are user processes (those that execute user code).
All these processes can potentially execute concurrently, by multiplexing the CPU
among them.
Following are the activities performed by operating system as a part of
Process Management
1. Creating and deleting both user and system processes
2. Suspending and resuming processes
3. Providing mechanisms for process synchronization
4. Providing mechanisms for process communication
5. Providing mechanisms for deadlock handling.

2) Main Memory Management


The services provided under Memory Management (MM) are directed to
keeping track of memory and allocating/deallocating it to various processes. The
Operating System keeps a list of free memory locations. (Initially, after the booting
but before any process starts, the full memory, excepting the part occupied by the
Operating System itself is free.) Before a program is loaded in the memory from the
disk, this module (MM) consults this free list, allocates the memory to the process,
depending upon the program size, and updates the list of free memory.
The main memory is central to the operation a modem computer system. Main
memory is a large array of words or bytes, ranging in size from hundreds of thousands
to billions. Each word or byte has its own address. Main memory is storage of
quickly accessible data shard by the CPU and I/O devices. The central processor
reads instructions
From math memory during the instruction-fetch cycle and it both reads and
writes data from main memory during the data-fetch cycle. The I/O operations
Implemented via DMA also read and write data in main memory. The main
memory is generally the only large storage device that the CPU is able to address
and access directly.
For example for the CPU to process data from 10
disk
A. That data must first be transferred to main memory by CPU-generated I/O
calls. B. Equivalently, instructions must be in memory for the CPU to execute
them.
For a program to be
executed
A. It must be mapped to absolute addresses and loaded into memory
B. As the program executes, it accesses program instructions and data from
memory by generating these absolute addresses.
C. Eventually, the program terminates, its memory space is declared available, and
D. The next program can be loaded and executed.
To improve both the utilization of the CPU and the speed of the computer’s
response to its users,
A. We must keep several programs in memory.

11
B. Memory Management Scheme.
Many different memory-management schemes are available, and the effectiveness
of the different algorithms depends on the particular situation. Selection of memory-
management scheme for a specific system depends on many factors especially on the
hardware design of the system.
Following are the activities performed by operating system as a part of Main Memory
Managem
ent
1. Keeping track of which parts of memory are currently being used and by whom
2. Deciding which processes are to be loaded into memory when memory space
becomes available
3. Allocating and deallocating memory space as needed

3) IO
Managem
ent
One of the purposes of an operating system is to hide the peculiarities of specific
hardware devices from the user. For example, in UNIX, the specialties of I/O devices are
hidden from the bulk of the operating system itself by the I/O subsystem. The I/O
subsystem consists of
1. A memory-management component that includes buffering, caching, and spooling
2. A general device-driver interface
3. Drivers for specific hardware devices.
Only the device driver knows the peculiarities of the specific device to which it
is assigned.

4) Secondary storage management


Secondary Memory Management
The main purpose of a computer system is to execute programs. These programs
with the data they access must be in main memory or primary storage during execution.
Since main memory is too small to accommodate all data and programs and because the
data that it holds are lost when power is lost i.e. they are volatile, hence system is
provided secondary storage to back up main memory. Most modern computer systems
use disks as the on-line storage medium, for both programs and data. Most programs—
including compilers, assemblers, sort routines, editors, and formatters—are
backup(Stored) on a disk until loaded into memory and then use the disk as both the
source and destination of their processing. Hence the proper management of disk 12
storage is of central importance to a computer system.
Following are the activities performed b y operating system as a part of Secondary
Memory
Management
1. Free-space management
2. Storage allocation
3. Disk scheduling
Since this secondary storage is used very frequently, it must be used efficiently. Else the
speed of operation of a computer may get degrades as is also depend on the speeds
of the disk subsystem and of the algorithms that manipulate that subsystem.
Process Management
A program does nothing unless its instructions are executed by a CPU. A process can be
thought of as a program in execution. Example of Process,
1. A time-shared user program such as a compiler is a process.

13
r r

2. A word-processing program being run by an individual user on a PC is a process.


3. A system task, such as sending output to a printer, is also a process.
Hence we can consider a process to be a job or a time-shared program
The function of the Operating System in this regard is to keep track of all the
competing processes (we will call a running program, a process), schedule them (i.e.
sequence them), dispatch (i.e. run or execute) them one after the other, but while doing
so, try to give each user an impression that he has the full control of the CPU.
A process needs certain resources—including CPU time, memory, files, and I/O
devices—to accomplish its task. These resources are either given to the process when it
is created, or allocated to it while it is running. In addition to the various physical and
logical resources that a process obtains when it is created, various initialization data (or I
may be passed along. For example
Consider a process whose function is to display the status of a file on the screen of
a terminal. What will happen..
4. The process will be given as an input the name of the file,
5. Will execute the appropriate instructions and system calls to obtain display on
the terminal the desired information.
6. When the process terminates the operating system will reclaim any reusable
resources.
Program v ersus Process
A program by itself is not a process; a program is a passive entity such as the
contents of a file stored on disk, whereas a process is an active entity, with a program
counter specifying the next instruction to execute. The execution of a process must be
sequential. The CPU executes one instruction of the process after another, until the
process completes.
Further at any time at most one instruction is executed on behalf of the process.
Thus although two processes may be associated with the same program, they are
nevertheless considered two separate execution sequences. It is common to have a
program that spawns many processes as it runs.
A process is the unit of work in a system. Such a system consists of a collection of
processes, some of which are operating-system processes (those that execute system
code) and the rest of which are user processes (those that execute user code). All these
processes can potentially execute concurrently, by multiplexing the CPU among them.
Following are the activities performed by operating system as a part of Process
Management
1. Creating and deleting both user and system processes 14
2. Suspending and resuming processes
3. Providing mechanisms for process synchronization
4. Providing mechanisms for process communication
5. Providing mechanisms for deadlock handling.

Main Memory Management


Amst ed services provided under Memory Management (MM) are directed to keeping
track of memory and allocating/deallocating it to various processes. The Operating
System keeps a list of free memory locations. (Initially, after the booting but before any
process starts, the full memory, excepting the part occupied by the Operating System
itself is free.) Before a program is loaded in the memory from the disk, this module (MM)

15
r r

consults this free list, allocates the memory to the process, depending upon the program
size, and updates the list of free memory.
The main memory is central to the operation a modem computer system. Main
memory is a large array of words or bytes, ranging in size from hundreds of thousands
to billions. Each word or byte has its own address. Main memory is storage of quickly
accessible data shard by the CPU and I/O devices. The central processor reads
instructions
ü From math memory during the instruction-fetch cycle and it both reads and
writes data from main memory during the data-fetch cycle. The I/O operations
ü Implemented via DMA also read and write data in main memory. The main
memory is generally the only large storage device that the CPU is able to address
and access directly.
For example for the CPU to process data from disk
A. That data must first be transferred to main memory by CPU-generated I/O calls.
B. Equivalently, instructions must be in memory for the CPU to execute them.
For a program to be executed
A. It must be mapped to absolute addresses and loaded into memory
B. As the program executes, it accesses program instructions and data from memory
by generating these absolute addresses.
C. Eventually, the program terminates, its memory space is declared available, and
D. The next program can be loaded and executed.

To improve both the utilization of the CPU and the speed of the computer’s response
to its users,
A. We must keep several programs in memory.
B. Use Memory management scheme
Many different memory-management schemes are available, and the effectiveness of
the different algorithms depends on the particular situation. Selection of memory-
management scheme for a specific system depends on many factors especially on the
hardware design of the system.
Following are the activities performed by operating system as a part of Main Memory
Management
1. Keeping track of which parts of memory are currently being used and by whom
2. Deciding which processes are to be loaded into memory when memory space
becomes available
3. Allocating and deallocating memory space as needed
16
File Management
Computers can store Information on several different types of physical media like
magnetic tape, magnetic disk and optical disk. Each of these media has its own
characteristics and physical organization. Each medium is controlled by the device and
this device also has unique characteristics. These properties Include access speed,
capacity, and data transfer rate and access method.
A file is a collection of related information defined by its creator. Commonly, files
represent programs (both source and object forms) and data. Data files may be numeric,
alphabetic, or alphanumeric. Files may be free-form (for example, text files), or may be
formatted rigidly (for example, fixed fields). A file consists of a sequence of bits, bytes,

17
r r

lines, or records whose meanings are defined by their creators. The concept of
a file is an extremely general one.
The operating system implements the abstract concept of a file by
managing mass
storage media, such as disks and tapes, and the devices that control them.
Also, files are normally organized into directories to ease their use. Finally,
when multiple users have access to files, we may want to control by whom
and in what ways (for example, read, write, append) files may be accessed.

Following are the activities performed by operating system as a part


of File Management
1. Creating and deleting files.
2. Creating and deleting directories.
3. Supporting primitives for manipulating files and directories.
4. Mapping files on to secondary storage.
5. Backing up files on storage media.

Secondary Memory
Management
The main purpose of a computer system is to execute programs. These
programs with the data they access must be in main memory or primary storage
during execution. Since main memory is too small to accommodate all data and
programs and because the data that it holds are lost when power is lost i.e.
they are volatile, hence system is provided secondary storage to back up
main memory. Most modern computer systems use disks as the on-line storage
medium, for both programs and data. Most programs— including compilers,
assemblers, sort routines, editors, and formatters—are backup(Stored) on a
disk until loaded into memory and then use the disk as both the source and
destination of their processing. Hence the proper management of disk
storage is of central importance to a computer system.
Following are the activities performed b y operating system as a part of
Secondary
Memory
Managem
18
r r

ent
➢ Free-space management
➢ Storage allocation
➢ Disk scheduling
Since this secondary storage is used very frequently, it must be used efficiently.
Else the speed of operation of a computer may get degrades as is also depend
on the speeds of the disk subsystem and of the algorithms that manipulate that
subsystem

19

You might also like