System calls provide the interface between a running program and the operating system. Any single CPU computer can execute only one instruction at a time.
System Calls
AU
May-17, 22
•
System calls provide the interface between a running program and the operating
system. Any single CPU computer can execute only one instruction at a time. If
a process is running a user program in user mode and needs a system service,
such UTD as reading a data from a file, it has to execute a instruction to
transfer control to the operating system.
• Operating system provides services and
system call provides interface to these services. System call is written in
language C and C++ as routines. System calls are performed in a series of
steps.
•
System call is a technique by which a program executing in user mode can
request the kernel's service.
•An application programmer interface is
a function definition that specifies how to
obtain a given service.
•
Fig. 1.12.1 shows the working of system call.
• When application program calls the
stub, trap instruction is executed and CPU switches to supervisor mode. Each
system call contains its identification number.
•
OS maintains the table of system call number. Operating system executes the
system call using that number.
•
When the function completes, it switches the processor to user mode and then
returns control to the user process.
A system call is an explicit request to
the kernel mode via a software interrupt. When user mode process invokes a
system call, the CPU switches to kernel mode and starts the execution of the
kernel function.
•
Making a system call is like making a special kind of procedure call. Only
system call enters the kernel and procedure call does not enter into the
kernel.
• Kernel implements many different
types of system calls. The user mode process must pass a parameter called the
system call number to identify the required system call. All system calls
return an integer value. In the kernel, positive or 0 values denote a
successful termination of the system call and negative values denote an error
condition.
• An API does not necessarily correspond
to a specific system calls.
1.
API could offer its services directly in user mode.
2. Single API function could make
several system calls.
3.
Several API functions could make the same system call.
• API supports a set of functions for
application programmer. It includes passing parameter to each function and
return values. API used by application programmer are as follows:
1. Windows system: win32 API
2.
POSIX system : POSIX API
3. Virtual machine: Java API.
• User function uses trap instruction for
using kernel services. Application programmer uses ordinary procedure call.
Operating system provides a library of user functions with name corresponding
to each actual system call. Each of these stub function contains a trap to the
operating system function.
•
Trap is also called system call interface.
• Three general methods are used to pass
parameters to the operating system.
a. Pass parameters in registers
b. Registers pass starting addresses of blocks
of parameters
C. Parameters can be placed, or pushed,
onto the stack by the program, and
popped
off the stack by the OS
• Fig. 1.12.2 shows passing of
parameters as a table
• System call is divided into following
types:
1. File management 2. Process
management
3. Interprocess communication 4. I/O device management
5. Information processing and
maintenance
1.
File management
• File management system calls are
create file, delete file, open file, close file, read file, write file,
get and set file attribute.
•
User can create a file using create() system call. File name with attributes
are required for creating and deleting a file through system call. After
creating a file, user can performs
various operations on the file.
•
Read, write, reposition are the operation performed on the file. File is closed
after finished using. Same type of operation is performed on directory.
• Every file has file attributes. File
attributes includes name of file, type of file, accounting information etc. To
perform any operation on the file, set file attribute and get file attribute
executed to check the attributes.
2.
Process management
• System calls for process management
are create, terminate, load, execute, abort, set and get process attributes.
Other system call for process management is wait for time, wait event, allocate
and free memory.
• In some situation user want to
terminate the currently running process abnormally then system call used. Other
reasons for abnormal process termination are error message generated, memory
dump, error trap.
• Operating system provides debugging
facility to determine the problem of dump. Dump is written to secondary storage
disk.
• Debugger is a one type of system
program. It provides facility for finding and correcting bug.
3.
Interprocess communication
• Pipe, socket, message passing and
shared memory are used for interprocess communication. Send message, receive
message, create and delete connection, attach remote device are the system
calls used in interprocess communication. •Shared memory: A process uses memory
for communication. One process will create a memory portion which other
processes can access. A shared segment can be attached multiple times by the
same process. Shared memory is the fastest form of IPC because data does not
need to be copied between processes.
•
A socket is a bidirectional communication device that can be used to
communicate with another process on the same machine or with a process running
on other machine.
•
Message passing: Two processes communicate with each other by passing messages. Message passing is direct and indirect communication. Indirect
communication uses mailbox for sending receiving message from other process.
4.
I/O device management
• System
calls for device management are request () device, release ( ) device, get of
nail and set device attributes, read, write etc.
•
Process needs several resources in its life time. When process request for
resources, request is granted if it is free otherwise request is rejected. Once
request is granted, control is transfer to the process.
5.
Information processing and maintenance
• System calls for this category is set
time and date, get time and date, get system data, get system data, get and set
process, file and device.
•
Most of the operating system provides system call for set and get the time and
date.
• This type of system call is used for
transferring information from user to operating system and vice versa.
University
Questions
1. Discribe system calls and system programs in detail with neat sketch. AU:May-17,Marks 5
2. List and explain five types of
system calls. AU:May-22,
Marks 6
Introduction to Operating Systems: Unit I: Introduction : Tag: : Introduction - Introduction to Operating Systems - System Calls
Introduction to Operating Systems
CS3451 4th Semester CSE Dept | 2021 Regulation | 4th Semester CSE Dept 2021 Regulation