0% found this document useful (0 votes)
13 views44 pages

Operating Systems Unit I

The document outlines a B.Tech course on Operating Systems, detailing prerequisites, objectives, and outcomes. It covers various operating system concepts, types, and structures, including process management, CPU scheduling, memory management, and file system operations. Additionally, it discusses the advantages and disadvantages of different operating systems such as batch, multiprogramming, time-sharing, and distributed systems.
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)
13 views44 pages

Operating Systems Unit I

The document outlines a B.Tech course on Operating Systems, detailing prerequisites, objectives, and outcomes. It covers various operating system concepts, types, and structures, including process management, CPU scheduling, memory management, and file system operations. Additionally, it discusses the advantages and disadvantages of different operating systems such as batch, multiprogramming, time-sharing, and distributed systems.
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

OPERATING SYSTEMS

[Link]. II Year II Sem. L T P C


3 0 0 3
Prerequisites:
1. A course on “Computer Programming and Data Structures”.
2. A course on “Computer Organization and Architecture”.

Course Objectives:
● Introduce operating system concepts (i.e., processes, threads, scheduling, synchronization,
deadlocks, memory management, file and I/O subsystems and protection)
● Introduce the issues to be considered in the design and development of operating system
● Introduce basic Unix commands, system call interface for process management, interprocess
communication and I/O in Unix

Course Outcomes:
● Will be able to control access to a computer and the files that may be shared
● Demonstrate the knowledge of the components of computers and their respective roles in
computing.
● Ability to recognize and resolve user problems with standard operating environments.
● Gain practical knowledge of how programming languages, operating systems, and
architectures interact and how to use each effectively.

UNIT - I
Operating System - Introduction, Structures - Simple Batch, Multiprogrammed, Time-shared,
Personal Computer, Parallel, Distributed Systems, Real-Time Systems, System components,
Operating System services, System Calls
Process - Process concepts and scheduling, Operations on processes, Cooperating Processes,
Threads

UNIT - II
CPU Scheduling - Scheduling Criteria, Scheduling Algorithms, Multiple -Processor Scheduling.
System call interface for process management-fork, exit, wait, waitpid, exec
Deadlocks - System Model, Deadlocks Characterization, Methods for Handling Deadlocks, Deadlock
Prevention, Deadlock Avoidance, Deadlock Detection, and Recovery from Deadlock

UNIT - III
Process Management and Synchronization - The Critical Section Problem, Synchronization
Hardware, Semaphores, and Classical Problems of Synchronization, Critical Regions, Monitors
Interprocess Communication Mechanisms: IPC between processes on a single computer system,
IPC between processes on different systems, using pipes, FIFOs, message queues, shared memory.

UNIT - IV
Memory Management and Virtual Memory - Logical versus Physical Address Space, Swapping,
Contiguous Allocation, Paging, Segmentation, Segmentation with Paging, Demand Paging, Page
Replacement, Page Replacement Algorithms.

UNIT - V
File System Interface and Operations -Access methods, Directory Structure, Protection, File System
Structure, Allocation methods, Free-space Management. Usage of open, create, read, write, close,
lseek, stat, ioctl system calls.
TEXT BOOKS:
1. Operating System Principles- Abraham Silberchatz, Peter B. Galvin, Greg Gagne 7th Edition,
John Wiley.
2. Advanced programming in the UNIX environment, W.R. Stevens, Pearson education.

REFERENCE BOOKS:
1. Operating Systems- Internals and Design Principles, William Stallings, Fifth Edition–2005,
Pearson Education/PHI
2. Operating System A Design Approach- Crowley, TMH.
3. Modern Operating Systems, Andrew S. Tanenbaum 2nd edition, Pearson/PHI
4. UNIX programming environment, Kernighan and Pike, PHI/ Pearson Education
5. UNIX Internals -The New Frontiers, U. Vahalia, Pearson Education.
UNIT I

INTRODUCTION

OPERATING SYSTEM

A computer system has many resources (hardware and software), which may be required to complete a
task. The commonly required resources are input/output devices, memory, file storage space, CPU, etc.
The operating system acts as a manager of the above resources and allocates them to specific programs
and users, whenever necessary to perform a particular task. Therefore the operating system is the
resource manager i.e. it can manage the resource of a computer system internally. The resources are
processor, memory, files, and I/O devices.
In simple terms, an operating system is an interface between the computer user and the machine.

It is very important for you that every computer must have an operating system in order to run other
programs. The operating system mainly coordinates the use of the hardware among the various system
programs and application programs for various users.
An operating system acts similarly like government means an operating system performs no useful
function by itself; though it provides an environment within which other programs can do useful work.
Below we have an abstract view of the components of the computer system.

• The Computer Hardware contains a central processing unit(CPU), the memory, and the
input/output (I/O) devices and it provides the basic computing resources for the system.
• The Application programs like spreadsheets, Web browsers, word processors, etc. are used to
define the ways in which these resources are used to solve the computing problems of the users.
And the System program mainly consists of compilers, loaders, editors, OS, etc.
• The Operating System is mainly used to control the hardware and coordinate its use
among the various application programs for the different users.
• Basically, Computer System mainly consists of hardware, software, and data. OS is
mainly designed in order to serve two basic purposes:
• The operating system mainly controls the allocation and use of the computing
System’s resourcesamong the various user and tasks.
• It mainly provides an interface between the computer hardware and the
programmer thatsimplifies and makes feasible for coding, creation of
application programs and debugging

Two Views of Operating System


User's View System
View

Operating System: User View


The user view of the computer refers to the interface being used. Such systems are designed
for one user to monopolize its resources, to maximize the work that the user is
performing. In these cases,the operating system is designed mostly for ease of use, with
some attention paid to performance, and none paid to resource utilization.

Operating System: System View


The operating system can be viewed as a resource allocator also. A computer system consists
of many resources like - hardware and software - that must be managed efficiently. The
operating system acts as the manager of the resources, decides between conflicting requests,
controls the execution of programs, etc.

Types of Operating System


Given below are different types of Operating System:

• Simple Batch System


• Multi programmed
• Time-Shared
• Personal Computer
• Parallel
• Distributed Systems
• Real Time Systems

STRUCTURES

SIMPLE BATCH

In a Batch Operating System, the similar jobs are grouped together into batches with the help
of some operator and these batches are executed one by one. For example, let us assume that
we have 10 programs that need to be executed. Some programs are written in C++, some in C
and rest in Java. Now, every time when we run these programs individually then we will have
to load the compiler of that particular language and then execute the code. But what if
we make a batch of these 10
programs. The benefit with this approach is that, for the C++ batch, you need to load the
compiler only once. Similarly, for Java and C, the compiler needs to be loaded only once
andthe whole batch gets executed.

The following batch processing actions are performed by a computer system running this
operating system:

• A job is a single unit made up of a pre-programmed set of data, commands, and


programs.
• The orders are processed in the order in which these are received, meaning first come,
first served.
• These jobs are saved in memory and run without the need for any manual input.
• The OS releases memory after a job is completed successfully.

The following image describes the working of a Batch Operating System.

The OS keeps track of the number of jobs and executes them one by one. Jobs are processed in
the order in which they are received. A batch is defined for each work set. When a job is
completed, the memory associated with it is released, and the work’s output is sent to an
output spool for printing or processing later. In a batch operating system, user engagement is
limited. When the system takes over the task from the user, the person is free to do other
things. You can also make use of the batch processing system to make changes to data in any
transactions or records.

Examples
• Payroll System
• Bank Invoice System
• Transactions Process
• Daily Report
• Research Segment
• Billing System

Advantages:
• The overall time taken by the system to execute all the programmes will be
reduced.
• The Batch Operating System can be shared between multiple users.
Disadvantages:
• Manual interventions are required between two batches.
• The CPU utilization is low because the time taken in loading and unloading of
batches is veryhigh as compared to execution time.

MULTI-PROGRAMMING

On a single processor computer, a multiprogramming OS can run many programs. In a


multiprogramming OS, if one program must wait for an input/output transfer, the other
programmes are ready to use the CPU. As a result, different jobs may have to split CPU time.
However, their jobs are not scheduled to be completed at the same time.
Multiprogramming’s main purpose is to manage all of the system’s resources. The file system,
transient area, command processor, and I/O control system are the main components of a
multiprogramming system.

Working of multi-programming

In the multiprogramming system, multiple users can complete their tasks at the same time, and
they can be saved in the main memory. While a programme is performing I/O operations, the
CPU may distribute time to other applications while in idle mode.

While one application waits for an I/O transfer, another is always ready to use the processor,
and multiple programmes may share CPU time. Although not all tasks are executed at the
same time, there may be multiple jobs operating on the processor at the same time, with parts
of other processes first being executed, followed by another
segment, and so on. As a result, a multiprogramming system’s overall purpose is to keep the
CPU busy unless and until some tasks in the job pool become available. As a result, a single
processor computer may run multiple programmes, and the CPU is never idle

Examples
• Apps like office, chrome, etc.
• Microcomputers like MP/M, XENIX, and ESQview.
• Windows O/S
• UNIX O/S

Advantages
• High and efficient CPU utilization.
• User feels that many programs are allotted CPU almost simultaneously.

Disadvantages
• CPU scheduling is required.
• To accommodate many jobs in memory, memory management is required

TIME-SHARING OPERATING SYSTEM

Time-sharing is a logical extension of multiprogramming. The CPU executes multiple


jobs by switching, among them, but the switches occur so frequently that the users can
interact with each program while it is running. An interactive computer provides direct
communication between the user and the system. The user gives instructions to the OS
or a program directly, using hardware, and waits for results.

A time-shared operating system uses CPU scheduling and multiprogramming to


provide each user with a small portion of a time-shared computer. Each user has at
least one separate program in memory. When a process executes, it executes for only a
short time before it either finishes or needs to perform input/output. In time-sharing
operating systems several jobs must be kept simultaneously in memory, so the system
must have memory management and protection.

Working of timesharing operating system

In a Multi-tasking Operating System, more than one processes are being executed at a
particular time with the help of the time-sharing concept. So, in the time-sharing environment,
we decide a time that is called time quantum and when the process starts its execution then the
execution continues for only that amount of time and after that, other processes will be given
chance for that amount of time only. In the next cycle, the first process will again come for
its execution and itwill be executed for that time quantum only and again next process will
come. This process will continue.
The following image describes the working of a Time-Sharing Operating System.

Advantages:
Since equal time quantum is given to each process, so each process gets equal opportunity
toexecute.
The CPU will be busy in most of the cases and this is good to have case.
Disadvantages:
1. Process having higher priority will not get the chance to be executed first
because the equalopportunity is given to each process.

Examples

Windows 2000 server


Windows NT server
Unix
Linux

Personal computer operating system provides a good interface to a single user.

• Personal computer operating systems are widely used for word processing,
spreadsheets and Internetaccess.
• Personal computer operating system is made only for personal. You can say that your
laptops, computer systems, tablets etc. are your personal computers and the operating
system such as windows 7; windows 10, android, etc. are your personal computer
operating system.
• you can use your personal computer operating system for your personal purposes, for
example, to chatting with your friends using some social media sites, reading some
articles from internet, making some projects through Microsoft PowerPoint or any
other, designing your website, programming something, watching some videos and
movies, listening to some songs and many more.
A Personal Operating System is incredibly useful. By habituating high-value practices, you
make decisions about how you want to respond to life in advance. This makes life simpler. For
instance, having a morning routine means not burning precious creative energy in the first few
hours of your day by trying to decide how to organize your time. There are countless micro-
decisions that you make every day that can be removed by adopting a broader philosophy for
how you want to live your life.

Multiprocessor operating system utilizes multiple processors, which are connected


with physical memory, computer buses, clocks, and peripheral devices (touchpad,
joystick, etc). The main objective of using a multiprocessor OS is to consume high
computing power and increase the execution speed of the system.

Following are four major components, used in the Multiprocessor Operating System:

1. CPU – capable to access memories as well as controlling the entire I/O tasks.
2. Input Output Processor – I/P processor can access direct memories, and
every I/O processors have to be responsible for controlling all input and output
tasks.
3. Input/output Devices – These devices are used for inserting the input
commands, and producing output after processing.
4. Memory Unit – Multiprocessor system uses the two types of memory modules
- shared memory and distributed shared memory.
Advantages
• It saves time and money as many resources working together will reduce the
time and cutpotential costs.
• It can be impractical to solve larger problems on Serial Computing.
• It can take advantage of non-local resources when the local resources are finite.
• Serial Computing ‘wastes’ the potential computing power, thus Parallel
Computing makesbetter work of the hardware.
Disadvantages
• It addresses such as communication and synchronization between multiple sub- tasks
andprocesses which is difficult to achieve.
• The algorithms must be managed in such a way that they can be handled in a
parallelmechanism.
• The algorithms or programs must have low coupling and high cohesion. But
it’s difficult tocreate such programs.
• More technically skilled and expert programmers can code a parallelism- based
program well.

DISTRIBUTED OPERATING SYSTEM

A distributed operating system allows the distribution of entire systems on the couples
of center processors, and it serves on multiple real-time products as well as multiple
users. All processors are connected by valid communication mediums such as high-
speed buses and telephone lines, and in which every processor contains its local
memory along with other local processors.

The Distributed operating systems are also known as loosely coupled systems. They
involve multiple computers, nodes, and sites. These components are linked to each
other with LAN/WAN lines. A distributed OS is capable of sharing its computational
capacity and I/O files while allowing virtual machine abstraction to users.

S Soundarya(Assistant Professor)
Solaris
OSF/1
Micros
DYNIX
Locus
Mach

S Soundarya(Assistant Professor)
Advantages

A distributed operating system may share all resources from one site to
another, increasing data availability across the entire system.
It reduces the probability of data corruption because all data is replicated
across all sites.
The entire system operates independently of one another, and as a result, if one
site crashes, the entire system does not halt.
A distributed operating system is an open system since it may be accessed from
both local and remote locations.
It helps in the reduction of data processing time.
Most distributed systems are made up of several nodes that interact to make
them fault-tolerant. If a single machine fails, the system remains operational.

Disadvantages

The system must decide which jobs must be executed when they must be
executed, and where they must be executed. A scheduler has limitations, which
can lead to underutilized hardware and unpredictable runtimes.
It is hard to implement adequate security in a distributed operating system
since the nodes and connections must be secured.
The database connected to a DOS is relatively complicated and hard to manage
in contrast to a single-user system.
The underlying software is extremely complex and is not understood very well
compared to other systems.
The more widely distributed a system is, the more communication latency can
be expected. As a result, teams and developers must choose between
availability, consistency, and latency.
Gathering, processing, presenting, and monitoring hardware use metrics for big
clusters can be a real issue.

Examples

Solaris
OSF/1
Micros
DYNIX
Locus
Mach

REAL TIME OPERATING SYSTEM

It is developed for real-time applications where data should be processed in a fixed, small
duration of time. It is used in an environment where multiple processes are supposed to be
accepted and processed in a short time. RTOS requires quick input and immediate response,
e.g., in a petroleum refinery, if the temperate gets too high and
crosses the threshold value, there should be an immediateresponse to this situation to avoid the
explosion. Similarly, this system is used to control scientific instruments, missile launch
systems, traffic lights control systems, air traffic control systems, etc.

This system is further divided into two types based on the time constraints:

Hard Real-Time Systems:


These are used for the applications where timing is critical or response time is a major factor;
even a delay of a fraction of the second can result in a disaster. For example, airbags and
automatic parachutes that open instantly in case of an accident. Besides this, these systems
lack virtual memory.

Soft Real-Time Systems:


These are used for application where timing or response time is less critical. Here, the failure
to meetthe deadline may result in a degraded performance instead of a disaster. For example,
video surveillance (cctv), video player, virtual reality, etc. Here, the deadlines are not critical
for every taskevery time.

Advantages
• The output is more and quick owing to the maximum utilization of devices and system
• Task shifting is very quick, e.g., 3 microseconds, due to which it seems that
several tasks areexecuted simultaneously
• Gives more importance to the currently running applications than the queued
application
• It can be used in embedded systems like in transport and others.
• It is free of errors.
• Memory is allocated appropriately.

Disadvantages
• A fewer number of tasks can run simultaneously to avoid errors.
• It is not easy for a designer to write complex and difficult algorithms or
proficient programsrequired to get the desired output.
• Specific drivers and interrupt signals are required to respond to interrupts quickly.
• It may be very expensive due to the involvement of the resources required to work.

SYSTEM COMPONENTS

An operating system is a large and complex system that can only be created by partitioning
into small pieces. These pieces should be a well-defined portion of the system, which
carefully defined inputs, outputs, and functions.
Although Mac, Unix, Linux, Windows, and other OS do not have the same structure, most of
the operating systems share similar OS system components like File, Process, Memory, I/O
device management.

Let’s see each of these components in detail.

File Management
A file is a set of related information which is should define by its creator. It commonly
represents programs; both source and object forms, and data. Data files can be numeric,
alphabetic, or alphanumeric.

Function of file management in OS:


The operating system has the following important given activities in connections with file
management:

• File and directory creation and deletion.


• For manipulating files and directories.
• Mapping files onto secondary storage.
• Backup files on stable storage media

Process Management
• The process management component is a procedure for managing the many processes
that are running simultaneously on the operating system. Every software application
program has one or more processes associated with them when they are running.
• For example, when you use a browser like Google Chrome, there is a process running
for that browser program. The OS also has many processes running, which performing
various functions.
• All these processes should be managed by process management, which keeps
processes for running efficiently. It also uses memory allocated to them and shutting
them down when needed.
• The execution of a process must be sequential so, at least one instruction should be
executed on behalf of the process.

Functions of process management in OS:


The following are functions of process management.

• Process creation and deletion.


• Suspension and resumption.
• Synchronization process
• Communication process

I/O Device Management


One of the important use of an operating system that helps you to hide the variations of
specific hardware devices from the user.

Functions of I/O management in OS:

• It offers buffer caching system


• It provides general device driver code
• It provides drivers for particular hardware devices.
• I/O helps you to know the individualities of a specific device.

Network management

Network management is the process of administering and managing computer


networks. It includes performance management, fault analysis, provisioning of
networks, and maintaining the quality of service.

A distributed system is a collection of computers/processors that never share their own


memory or a clock. In this type of system, all the processors have their local Memory, and the
processors communicate with each other using different communication lines, like fiber optics
or telephone lines.

The computers in the network are connected through a communication network, which can be
configured in a number of different ways. With the help of network management, the network
can be fully or partially connected, which helps users to design routing and connection
strategies that overcome connection and security issues.
Functions of Network management:

• Distributed systems help you to various computing resources in size and


function. They may involve microprocessors, minicomputers, and many
general-purpose computer systems.
• A distributed system also offers the user access to the various resources the
network shares.
• It helps to access shared resources that help computation to speed-up or offers data
availability and reliability.

Main Memory management


Main Memory is a large array of storage or bytes, which has an address. The memory
management process is conducted by using a sequence of reads or writes of specific memory
addresses.

In order to execute a program , it should be mapped to absolute addresses and loaded inside
the Memory. The selection of a memory management method depends on several factors.

However, it is mainly based on the hardware design of the system. Each algorithm requires
corresponding hardware support. Main Memory offers fast storage that can be accessed
directly by the CPU. It is costly and hence has a lower storage capacity.
However, for a program to be executed, it must be in the main Memory.

Functions of Memory management in OS:


An Operating System performs the following functions for Memory Management:

• It helps you to keep track of primary memory.


• Determine what part of it are in use by whom, what part is not in use.
• In a multiprogramming system, the OS takes a decision about which process will
get Memory and how much.
• Allocates the memory when a process requests
• It also de-allocates the Memory when a process no longer requires or has been
terminated.

Secondary-Storage Management
The most important task of a computer system is to execute programs. These programs, along
with the data, help you to access, which is in the main memory during execution.

This Memory of the computer is very small to store all data and programs permanently. The
computer system offers secondary storage to back up the main Memory. Today modern
computers use hard drives/SSD as the primary storage of both
programs and data. However, the secondary storage management also works with storage
devices, like a USB flash drive, and CD/DVD drives.

Programs like assemblers, compilers, stored on the disk until it is loaded into memory, and
then use the disk as a source and destination for processing.

Functions of Secondary storage management in OS:


Here, are major functions of secondary storage management in OS:

• Storage allocation
• Free space management
• Disk scheduling

Security Management
The various processes in an operating system need to be secured from each other’s activities.
For that purpose, various mechanisms can be used to ensure that those processes which want
to operate files, memory CPU, and other hardware resources should have proper authorization
from the operating system.

For example, Memory addressing hardware helps you to confirm that a process can be
executed within its own address space. The time ensures that no process has control of the
CPU without renouncing it.

OPERATING SYSTEM SERVICES

An operating system executes programs and makes the process of solving them easier. It also
makes the computer system easier to use and helps the user use the computer hardware
efficiently. Apart from these, it also provides an array of services both to the users and the
programs.

Services of Operating System

The OS is the resource manager of a system. Thus, there are multiple services it provides in
order to have an efficient system that can utilize these resources to the fullest. Following are
the services provided by operating systems:
1. User Interface
• An interface is required to communicate with the user. Then it can either be a
Command Line Interface or a Graphical User Interface.

• There is also a third kind that is Batch Based Interface which is usually overlooked. It
uses commands to manage the commands entered into files and then these files get
executed.
• As for the first two, Command Line Interface commonly uses text commands input by
the users to interact with the system. These commands can also be given using a
terminal emulator, or remote shell client.
• A Graphical User Interface (GUI) allows users to interact with the computer system
or any other computer-controlled device.
• A GUI usually consists of all the graphical icons displayed on a computer screen,
visual indicators like widgets, texts, labels, and text navigation. Thus, a user can
directly perform actions with a click of the mouse or keyboard.

2. Program Execution
The OS loads a program into memory and then executes that program. It also makes sure that
once started that program can end its execution, either normally or forcefully. The major steps
during program management are:

• Loading a program into memory.


• Executing the program.
• Making sure the program completes its execution.
• Providing a mechanism for:
1. process synchronization.
2. Process communication.
3. Deadlock handling.
3. File System Manipulation
A program is read and then written in the form of directories and files. These files can be
stored on the storage disk for the long term. The OS allows the users to create and delete files,
duplicate these files, and search files and their information or properties.

It also does permission management for these files i.e., allowing or denying access to these
files or directories based on the file ownership.

4. I/O Operations
I/O operations are required during the execution of a program. To maintain efficiency and
protection of the program, users cannot directly govern the I/O devices instead the OS allows
to read or write operations with any file using the I/O devices and also allows access to any
required I/O device when required.

5. Communication systems
Processes need to swap information among themselves. These processes can be from the same
computer system or different computer systems as long as they are connected through
communication lines in a network.

This can be done with the help of OS support using shared memory or message passing. The
OS also manages routing, connection strategies, and the problem of contention and security.

6. Resource Allocation
When multiple users or multiple jobs run on a system concurrently, the resources need to be
allocated equally to all of them.

CPU scheduling is used to allocate resources fairly and for the better utilization of the CPU.
These resources may include CPU cycles, main memory storage, file storage, and I/O devices.

7. Error Detection
Errors may occur in any of the resources like CPU, I/O devices, or memory hardware. The OS
keeps a lookout for such errors, corrects errors when they occur, and makes sure that the
system works uninterruptedly.

8. Accounting
This keeps a check of which resource is being used by a user and for how long it is being
used. This is usually done for statistical purposes.
9. Protection and Security
This is to ensure the safety of the system. Thus, user authentication is required to access a
system. It is also necessary to protect a process from another when multiple processes are
running on a system at the same time.

The OS controls the access to the resources, protects the I/O devices from invalid access, and
provides authentication through passwords.

10. Command Interpretation


The OS understands and interprets commands that are input by the user and displays the input
accordingly. Multiple command interpreters can be supported by an OS and they do not
necessarily need to run in kernel mode.

If the interpreter is separate from the kernel then you can modify the interpreter and prevent
any unauthorized access into the system.

11. Resource Manager


The OS manages resources such as processor, memory, I/O devices etc efficiently. It allocates
resources to processes and administers running programs to ensure user satisfaction.

It also decides the time at which a program should run, the amount of memory allocated for
execution, where to save a file, and much more.

Apart from these basics, there are some more services the OS provides that are a part of
resource management. These are:

a. Process Management
when multiple processes run simultaneously on a system, the OS help manage them in order to
enhance system performance. Apart from this, the OS also manages printer spooling, virtual
memory, swapping, etc. and CPU scheduling is used to allocate resource

Major activities regarding process management are:


1. Creates and deletes processes.
2. Suspends and re-activates processes.
3. A mechanism for

 process synchronization
 process communication
 deadlock handling

b. Main-Memory Management
This deals with the primary, secondary, and virtual memory and increases the amount of
memory available for each process. In order to perform program execution, it is necessary to
load the program into the main memory.
The OS ensures that there is enough memory for a process to execute and different locations
of memory are being used properly for effective execution of processes.

During execution, the memory manager tracks available memory locations, where processes
can be allocated or unallocated.

c. Secondary-Storage Management
Primary and cache storage are volatile memories thus, the data is lost once power is turned
off.
Moreover, main memory cannot accommodate all data and programs so secondary storage is
needed as a backup like tape drives, disk drives, and other media. This provides easy access
to the files and folders in the secondary storage using disk scheduling algorithms.

OS manages free space on the secondary storage devices, allocates storage space to new files,
schedules memory access requests, and creates and deletes files.

d. Network Management
The OS works as a network resource manager when multiple systems form a network or in a
distributed system. The processors communicate through network lines called networks.
Today’s networks are usually based on client-server configuration where a client is the
program running on the local machine requesting a service and a server is the program
running on the remote machine providing a service.

SYSTEM CALLS

A system call is a mechanism that provides the interface between a process and the operating
system. It is a programmatic method in which a computer program requests a service from
the kernel of the OS.

System call offers the services of the operating system to the user programs via API
(Application Programming Interface). System calls are the only entry points for the kernel
system.
Example of System Call
For example if we need to write a program code to read data from one file, copy that data into
another file. The first information that the program requires is the name of the two files, the
input and out0put files.

In an interactive system, this type of program execution requires some system calls by OS.

 First call is to write a prompting message on the screen


 Second, to read from the keyboard, the characters which define the two files.

How System Call Works?


Here are the steps for System Call in OS:

As you can see in the above-given System Call example diagram.

Step 1) The processes executed in the user mode till the time a system call interrupts it.
Step 2) After that, the system call is executed in the kernel-mode on a priority basis.
Step 3) Once system call execution is over, control returns to the user mode.,
Step 4) The execution of user processes resumed in Kernel mode.

Why do you need System Calls in OS?


Following are situations which need system calls in OS:

 Reading and writing from files demand system calls.


 If a file system wants to create or delete files, system calls are required.
 System calls are used for the creation and management of new processes.
 Network connections need system calls for sending and receiving packets.
 Access to hardware devices like scanner, printer, need a system call.

Types of system calls

Process Control
This system calls perform the task of process creation, process termination, etc.

Functions:

 End and Abort


 Load and Execute
 Create Process and Terminate Process
 Wait and Signal Event
 Allocate and free memory

File Management
File management system calls handle file manipulation jobs like creating a file, reading, and
writing, etc.

Functions:

 Create a file
 Delete file
 Open and close file
 Read, write, and reposition
 Get and set file attributes

Device Management
Device management does the job of device manipulation like reading from device buffers,
writing into device buffers, etc.
Functions:

 Request and release device


 Logically attach/ detach devices
 Get and Set device attributes

Information Maintenance
It handles information and its transfer between the OS and the user program.

Functions:

 Get or set time and date


 Get process and device attributes

Communication:
These types of system calls are specially used for interprocess communications.

Functions:

 Create, delete communications connections


 Send, receive message
 Help OS to transfer status information
 Attach or detach remote devices

Example of System Calls in Windows and Unix

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()
Rules for Passing Parameters in System Call

1. The floating-point parameters can’t be passed as a parameter in the system call.


2. Only a limited number of arguments can be passed in the system call.
3. If there are more arguments, then they should be stored in the block of memory
and the address of that memory block is stored in the register.
4. Parameters can be pushed and popped from the stack only by the operating
system.

Important System Calls Used in OS

wait()
In some systems, a process needs to wait for another process to complete its execution. This
type of situation occurs when a parent process creates a child process, and the execution of the
parent process remains suspended until its child process executes.

The suspension of the parent process automatically occurs with a wait() system call. When the
child process ends execution, the control moves back to the parent process.

fork()
Processes use this system call to create processes that are a copy of themselves. With the help
of this system Call parent process creates a child process, and the execution of the parent
process will be suspended till the child process executes.

exec()
This system call runs when an executable file in the context of an already running process that
replaces the older executable file. However, the original process identifier remains as a new
process is not built, but stack, data, head, data, etc. are replaced by the new process.

kill():
The kill() system call is used by OS to send a termination signal to a process that urges the
process to exit. However, a kill system call does not necessarily mean killing the process and
can have various meanings.

exit():
The exit() system call is used to terminate program execution. Specially in the multi- threaded
environment, this call defines that the thread execution is complete. The OS reclaims resources
that were used by the process after the use of exit() system call.
Short note on system call

System call is the interface through which the process communicates with the
system call.
Computer system operates in two modes: User Mode and Kernel Mode
Process executes in user mode, and when a system call is made, the mode is
switched to kernel mode. Once the system call execution is completed, the
control is passed back to the process in user mode.
System calls in OS are made by sending a trap signal to the kernel, which reads
the system call code from the register and executes the system call.
Major type of system calls are Process Control, File Management, Device
Management, Information maintenance and Communication.
Rules for parameter passing while making a system call is it should not be a
floating number, a limited number of arguments should be passed and if
arguments are more, they should be stored in memory block and address of that
memory block should be passed, and the push, pop operations from the stack
will be made only by the operating system.
wait(), fork(), exec(), kill() and exit() are few important system calls of our
computer system.

You might also like