OS System Calls

A system call is an interface between the user program and the operating system. The program asks for different services and in response the OS invoke a set of system calls to fulfill the request.

Advertisements

What is a system call?

A system call is written in either assembly language or a high level such as C, Pascal and so on. If high-level language is used, then system calls are predefined functions or subroutines that can be invoked directly by the OS.

For example,

A user wants to copy information from an input file to an output file. There are three stages to this task listed below:

  1. Input-Output file names
  2. Open the files and perform read-write
  3. Close all files

Each of the above stages requires the OS to provide necessary services. The OS request for the input file name which will invoke a set of system calls and if the file already exists, then continue to the next stage.  Suppose output file exists then OS will delete it and create a new file.

To open the file an open() system call is invoked, followed by reading () and write() call to perform the read-write operation. You may need to supply the parameters for a system call, rather than calling it directly in some OS.

Once the task is completed, the files are closed using close() system call.

In case of errors, interrupts, or unexpected termination of a system call, another set of system call respond to the errors by reporting it to the user on the computer screen.

Passing parameter to system calls

There are three ways to pass parameters to OS (system calls):

  1. The parameter passed to registers
  2. Parameters stored in block or table in memory and the address of the block is passed to OS.
  3. The parameter is pushed on or off the stack by OS
Parameter for System call
Figure 1 – Parameter for a System call

Types Of System Calls

The system calls are divided into the following types:

  • Process and job control
  • File manipulation
  • Device manipulation
  • Information maintenance
  • Communication

Process and Job Control System Calls

These types of system calls are related to process and job. The process either terminates normally (end) or abnormally(abort). If the process terminates abnormally that causes an error trap, a memory dump is generated an error is reported. The memory dump available on disk can be used for debugging. The process terminates and transfers control to the command interpreter which continue the execution of the next command. In a batch system, the command interpreter skips the job and continue with the next job. In a GUI based system, popup reports and asks for further action.

A process can load (load()) and execute (execute()) another program or process. The control is returned to the old process when the new process terminates. We save the memory image of the old program files so that next time it calls the new program again when executed.

If both old and new program runs concurrently, it means that a new process is created. You can create a process(create() or submit job) explicitly. When we create process, we should be able to control attributes of the process such as getting attributes(get process attribute) or reset (set process attribute) the attributes of the process.

A process must wait(wait time) for sometimes for other processes to finish or it must wait for some event (wait event) to happen before continue with the execution. A process must signal other process of events by signal (signal event).

Two process running concurrently share data and to avoid conflict one of the process lock the shared data to avoid inconsistencies in updates. This is done using aquire lock and release lock command.

Advertisements

Examples:

We give two examples for process control calls – MS-DOS System and FreeBSD UNIX.

MS-DOS is single user system that runs program directly and does not create new processes. The program runs and terminates successfully, or an error trap happens which is saved to memory. The command interpreter reloads and display error to the user.

Figure 2 - MS-DOS
Figure 2 – MS-DOS

FreeBSD system is time-sharing or multi-tasking system. Each user who logs into the system gets a shell which is similar to MS-DOS command interpreter. The command interpreter request user input and runs the program. A new process is created using fork() system call and the selected program is run using exec() call. Either the process completes, or it runs in background, while the shell waits for next command. The user can run another program.

Figure 3 - Multi-tasking System
Figure 3 – Multi-tasking System

The process terminates using exit() system call which return a 0 to parent process.

File Management System calls

there are several system calls that deals with files. We should be able to create and delete files. The system call may require file name and sometimes few attributes. The must be opened to perform read, write, or reposition (rewinding or skipping the end of file). After the job is done the file must be closed.

The operating system provides system calls to manipulate file or directory attributes. The most important system calls are getting file attribute and set file attribute.

Some OS provides APIs to move and copy files using system calls. There are system programs using code and API to do those tasks.

Device Management System Calls

A process requires resources such as memory, disk, files access, etc. If resources are available the system process continues to return the control to the user process. Otherwise, the process waits for the resources until its available.

Each resource can be thought of as a physical device(disk) or virtual device (files). In a multitasking system, the user needs to request a resource to exclusively use it and release it after use.

Once device access is granted, we can read, write, or reposition the device. I/O devices and files are almost identical to OS and combined into device structure file, hence there are a common set of system calls for both as in case of UNIX. Otherwise, device files are kept in separate directories, given special names, or attributes to identify them.

Information Maintenance System Calls

These types of system call transfer information between the user program and the operating system. For example, the system call returns current date and time, OS version number, free disk space, free memory, etc.

When a program crashes a set of system call creates a memory dump useful in debugging the program. An operating system provides a time profile of a program that indicates the time spent at a location or location set. When a timer interrupt happens the value of the program counter is recorded which gives the time statistics of the program.

Communication System Calls

The process must communicate with each other for co-operation.  There is two such model – Message passing and Shared memory. The system calls of this type help in interprocess communication. Inter-process communication is a topic for another article.

References

  • Abraham Silberschatz, Peter B. Galvin, Greg Gagne (July 29, 2008) Operating SystemConcepts, 8 edn., Wiley.
  • Tanenbaum, Andrew S. (March 3, 2001) Modern Operating Systems, 2nd edn., : Prentice Hall.
  • Sweta Verma (2009) Krishna’s Operating System, Meerut: Krishna Prakashan Media (P) Ltd.

Advertisements

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.