System Calls
Operating System
(OPS – 22516)
CO 5 I
2020 - 2021
Operating system can be defined as :
1. Operating system is program which acts as an interface
between computer user (or application program) and
computer hardware and provides a convenient
environment for user.
2. Operating system is a manager of all the resources of
the computer system
3. Operating system controls all the errors which are
encountered in the system.
4. Protect the system from incorrect or malicious
programs and users.
Goals and Objectives of Operating System
Goals of Operating System
The primary goal of Operating system is to provide
convenience for user.
The secondary goal of Operating system is to utilise computer
system efficiently.
Operating system are designed to be convenient and to
be efficient.
Objectives of the Operating system are :
I. Provide convenience to user
2. Efficient utilisation of all the computer system resources
3. Control the errors in the system.
Thus an operating system,
Is a program that manages computer hardware
Provides an environment for execution of user programs
Acts as an intermediary/ interface between computer user and
computer hardware
Components of Operating System
Operating System includes following components
1. Process Management
2. Memory Management
3. Input and Output Management
4. Secondary Storage Management
5. File System Management
Each component provides functionality related to each
resource
Services
service
/ˈsəːvɪs/
the action of helping or doing work for someone.
E.g. "millions are involved in voluntary service“
a system supplying a public need such as transport, communications, or
utilities such as electricity and water.
E.g. "a regular bus service“
When you go out for dinner in a hotel, waiter provides you service
You decides menu after discussing it with Chef / Master
But waiter serve customers at their tables in a restaurant
As a customer, you don’t need to worry about –
how food is being prepared, what is a raw material used, from where raw material
is procured, who is involved in cooking, who us chef, what are the contents, where
is it being prepared, Etc. etc.
You are interested in good quality food, best service, that will satisfy your
appetite
Reward : Satisfied customer
Waiter provides service to customer and at the same time his employer
also.
Operating System Services
On the same ground
Operating system provides services to
User and
System
Operating system provides an environment for execution
of programs.
Operating system provides certain services, to programs
and to the users of those programs.
Specific services provided by operating system differ from
one operating system to other.
But common services can be classified.
Computer System Organisation
At the
Highest
Level
At the
Lowest
Level
User 1 User 2 User 3 User n
Operating system
services are provided
App. App. 1. For convenience of users
Compiler Assemb-l
Program Program 2. To make programming
er
task of programmer
easier.
Operating System Therefore services provided by
Services to operating system, can be divided
into two sets as,
• User &
• System 1. One set of operating system
services which provides
functions that are helpful to
the user
2. Another set of operating
system services which
provides functions that
ensures efficient operations
of the system
OS Services
One set of operating system services which provides functions
that are helpful to the user as , (provides convenience to users)
1. User Interface
2. Program Execution
3. I/O operations
4. File System manipulation
5. Communications
6. Error Detection
B) Another set of operating system services which provides
functions that ensures efficient operations of the system
7. Resource allocation
8. Accounting
9. Protection and Security
A View of Operating System Services
How operating system provides these
services ?
Services can be provided in many different ways
TWO basic methods of providing services are –
1. System Calls
2. System Programs
1. System Calls
System Call –
Is used by application program (user) to request services from
the operating system
It is nothing but a set of instructions exclusively used by
operating system to provide services to application program
(user)
Definition : System calls are an interface between a running
program (process) and operating system
Why System calls are needed ?
An operating system can access a system’s hardware
directly
But User program is not given direct access to the
hardware
This ensure the security of kernel
Why system calls are needed ?
User do not
have direct
Application access to
program can not hardware
access hardware To use hardware,
directly. user needs
application
programs.
So, application program needs a help of operating
system
BUT Operating System can not be accessed directly by
application program
At any instance, there are
multiple processes available in
main memory and may need of
help of operating system.
While providing services to
every requesting process
operating system has
To protect itself and,
Also manage system resources
effectively
Most of the processes needs
common services.
Therefore, every requesting process has to make a call to
operating system for obtaining services.
Such calls, referred as system calls, are used to provide services of
operating system to requesting processes
System Call Interface
A System Call Interface is provided between – application program
under execution and operating system
System Calls
(Also called as Supervisory calls, SVC)
Provides an interface to the services made available by
operating system
Definition :
System calls provide an interface between a running program
(process) and operating system.
The most fundamental levels of services are handled through
the use of system calls.
These are generally available as a routine
And are written in C, C++
But system calls for certain low level tasks (for e.g. tasks
where hardware must be accessed directly) are written using
assembly language instructions
Commands issued by user, at command line interpreter or
using GUI, are normally converted into, and executed as a
series of system calls.
How system call works?
System call executes in system mode (kernel mode)
Types of System Calls
System calls can be grouped into following
major categories
System calls for
1. Process Control
2. File Manipulation
3. Device Management
4. Information Maintenance
5. Communications
6. Protection
1. System calls for Process Control
The purpose of a computer systems is to allow the user to execute programs.
So the operating systems provides an environment where the user can
conveniently run programs.
The user does not have to worry about the memory allocation or multitasking
or anything.
These things are taken care of by the operating systems.
Operating system must be able to load the program into memory and run that
program.
Program must be able to end its execution either normally or abnormally, indicating
error.
The five major activities of an operating system in regard to process
management are
1. Creation and deletion of both - user and system processes
2. Suspension and resumption of processes
3. Providing a mechanism for process synchronization
4. Providing a mechanism for process communication
5. Providing a mechanism for deadlock handling
System Calls for Process Control
1. Create process, terminate process
2. Load, execute
3. End, abort
4. Get process attributes, set process attributes
5. Wait for time
6. Wait event, signal event
7. Allocate memory, free memory
..\Notes\Chapter 2 OS Services _ System Calls.pdf
Some system calls are also used by OS in debugging a
program which dumps the memory to determine the
causes of problems or program traces (trace – is a list
each instruction as it is executed)
Examples of system calls for process control
In UNIX,
fork( ) system call is used – to create and load a process
exec( ) system call is used – for execution of a process
exit( ) system call is used – to terminate a process
2. File Manipulation System Call
Operating system shall provide theses services as
program needs –
to create and delete files and directories,
to read and write,
to search and list file information.
Some programs include permission management to allow
access or deny access to files and directories.
The operating systems provides this service.
The user does not have to worry about secondary
storage management.
Examples of File Manipulation operations –
• Create a file
• Open a file
• Copy and paste
• Move a file (Cut and Paste)
• Rename a file
• Reposition a file
• Append a file
• Modify the file
Examples of File Attributes –
• Name of file, location of file,
• Type of file,
• Date of creation, modification,
accessed
• File permissions like – read only,
archieved
• Security permissions
• Etc.
• Etc.
System call for File Manipulation
Few common types of system calls dealing with files are
1. Create a file
2. Delete a file
3. Open, close
4. Read, write, reposition
5. Get file attributes, set file attributes
..\Notes\Chapter 2 OS Services _ System Calls.pdf
3. Device Management System Calls
Services related to I/O Device Management
Each program requires an input and produces output.
This involves the use of I/O.
The operating systems hides the user the details of underlying
hardware for the I/O.
All the user sees is that the I/O has been performed without
any details.
So the operating systems by providing I/O makes it convenient
for the users to run programs.
A running program may require I/O.
For efficiency and protection, users usually can’t control I/O
devices directly.
Therefore operating system must provide a means to do I/O.
To complete its execution, process needs several Input,
output devices
Some are physical like – printer, tapes
Some are logical like – files
If resources are free (i.e. available), they are allocated (i.e.
granted) to requesting process.
To obtain rights to use these devices
Process needs – to request a device
If device is free – operating system allocates that device to requesting
process
On allocation – process uses (consume) the device
(i.e. Process can read, write and reposition the device)
Once it task related to device is completed, process releases the
device
Such OS provides – managed access to devices
Few OS provide – unmanaged access to devices causing
deadlock (OS has no control on allocation of resources)
Same operations can be performed on files
There is similarity between operations on I/O devices
and Files
Therefore most of the OS, like UNIX, provides combined
file – device structure.
Devices are also treated as files
4. Information Maintenance System Calls
OS collects various type
of information for
controlling operations and
managing resources
For e.g.
System date and time
Resource Attributes
Number of users using the
system
Etc.
Types of system calls for Information Maintenance
Get time or date
Information about
Set time or date System
Get system data, set system data
Get process data, set process data
Get process, file or device attributes Information about
Set process, file or device attributes processes
Most of OS have system calls for
To return information about system as –
The number of current users
The version number of operating system
The amount of free memory, disk space
And so on.
5. System calls for Communication
During its execution one process many need to
communicate with other process
Such processes can be present on same machine or on a
remote machine
Such communication is called as Inter Process
Communication (IPC)
TWO models are commonly used for IPS
a) Shared memory model
b) Message Passing model
Before communication can take place,
A connection must be opened
A name of other communicator (must be known)
Establish a connection
Send and receive message
Disconnect the connection after communication is over
System Calls for communication are –
1. Create, delete communication connection
2. Send, receive messages
3. Transfer status information
4. Attach or Detach remote devices
In a network,
Each computer has host name
by which it is commonly
known
Host has IP address used as a network identifier
Each process has a process name, and process ID (PID)
OS refers process by PID
System calls like –
1. Get host id, Get process id - are used obtain host and process ID
2. Accept connection – is used by recipient process to gives its
permission
3. read message and write message – are used to exchange messages
4. Close connection - is used to terminates connection
6. System Calls for Protection
Protection
Control access to resources
Get and set permissions
Allow and deny user access
System Calls used in Windows and Unix
Examples of System Call Implementation
Task is to copy a file from source to destination
C:\>copy <source file name> <destination file name>
Application Programming Interface (API)
Most of application developers
use API in their programs to
request services.
API are set of functions that
makes programming task easier.
THREE most common APIs available
to programmer are –
1. Win32 for Windows
2. POSIX for Unix, Linux, Mac OS X
3. Java API for Java Virtual Machine
The function that uses API, invokes the system calls on behalf of programmer.
There exist strong correlation between a function in the API and its associated system
call within the kernel.
How OS handles user application invoking a
system call ? (Run time support System)
Explicit use of system calls
Many High Level Languages like C allow system calls to be embedded in the
program
Which makes C suitable for writing system calls
For e.g.
A functions in C like –
exit( ) - used to terminate process normally
abort( ) - used to terminate process abnormally
Compiler substitutes it by a system call to kill or terminate a process
Some languages, like Java, C++, COBOL do not require explicit
use of system calls
In these cases, compiler substitutes system calls at proper places, wherever
necessary during compilation.
Why different compilers are
needed under different operating
system even if source
programming language is same ?
For e.g. programming language is C,
but operating is DOS, Windows,
UNIX, Linux.
Same source code need to be
recompiled in case operating system
differs.
Standard C Library Function
A standard C Library provides a
portion of the system call interface
for many versions of UNIX and
Linux.
C is having run time support system
( in which a set of functions built
into libraries included with a
compiler)
This support system provides a
system call interface.
This system intercepts function calls
and invokes necessary system call
within OS.
As shown above, a C program uses printf( ) function embedded in a
statement . C library intercepts this call and invokes necessary system
call(s) in operating system. In this case write( ) system is used to display a
string “Greetings” on standard output (monitor)