SYSTEM CALLS:
System calls provide the interface between a process and the operating system.
These calls are generally available as assembly-language instructions.
Some systems also allow to make system calls from a high level language, such as C, C++and
Perl (have been defined to replace assembly language for systems programming). As an example
of how system calls are used, consider writing a simple program to read data from one file and
to copy them to another file.
The first input that the program will need is the names of the two files:
o The input file
o The output file
Once the two file names are obtained, the program must open the input file and create the output
file.
Each of these operations requires another system call and may encounter possible error
conditions.
When the program tries to open the file, it may find that no file of that name exists or that the
file is protected against access.
If the input file exists, then we must create a new output file.
We may find an output file with the same name.
o This situation may cause the program to abort (a system call), or
o We may delete the existing file (another system call).
In an interactive system another option is to ask the user ( a sequence of system calls to output
the prompting message and to read response from the keyboard) whether to replace the existing
file or to abort the program.
Example of System Calls
Now that both the files are setup, we enter a loop that reads from the input file (a system
call) and writes to the output file (another system call).
Each read and write must return status information regarding various possible error conditions.
o On input,
the program may find that the end of file has been reached, or
that a hardware failure occurred in the read (such as a parity error).
o On output,
Various errors may occur, depending on the output device (such as no more
disk space, physical end of tape, printer out of paper).
Finally, after the entire file is copied, The program may close both files (another system call),
writes a message to the console (more system calls), and finally terminates normal (the final
system call).
System calls occur in different ways, depending on the computer in use.
Three general methods are used to pass parameters between a running program and the operating
system.
o Simplest approach is to pass parameters in registers.
o Store the parameters in a table in memory, and the table address is passed as a parameter
in a register (in the cases where parameters are more than registers).
o Push (store) the parameters onto the stack by the program, and pop off the stack by
operating system.
Parameter Passing via Table
TYPES OF SYSTEM CALLS
System calls can be grouped roughly in to five categories:
o Process control: load, execute, abort, end, create process, terminate process, get
process attributes, set process attributes, allocate and free memory, wait event, signal event.
o File management :create file, delete file, open, close, read, write, reposition, get file
attribute, set file attributes.
o Device management : request device, release device, read, reposition, write, get device
attributes, set device attributes, logically attach or detach device.
o Information maintenance : get time and date, set time and date, get system data, set system
data, get process file or device attributes, set process file or device attributes.
o Communications :create, close communication connection, send, receive messages, transfer
status information, attach or detach remote devices. Communication may take place using:
message passing model or
shared memory model
Communication models: (a) message passing model (b) shared
memory model