Table of contents | |
Introduction | |
How are system calls made? | |
How System Calls Work | |
Types of System Calls |
A system call is a way for a user program to interface with the operating system. The program requests several services, and the OS responds by invoking a series of system calls to satisfy the request. A system call can be written in assembly language or a high-level language like C or Pascal. System calls are predefined functions that the operating system may directly invoke if a high-level language is used.
In this article, you will learn about the system calls in the operating system and discuss their types and many other things.
When a computer software needs to access the operating system's kernel, it makes a system call. The system call uses an API to expose the operating system's services to user programs. It is the only method to access the kernel system. All programs or processes that require resources for execution must use system calls, as they serve as an interface between the operating system and user programs.
Below are some examples of how a system call varies from a user function.
There are various situations where you must require system calls in the operating system. Following of the situations are as follows:
Now, you will learn about all the different types of system calls one-by-one.
Examples of Windows and Unix system calls
There are various examples of Windows and Unix system calls. These are as listed below in the table:
Here, you will learn about some methods briefly:
open()
The open() system call allows you to access a file on a file system. It allocates resources to the file and provides a handle that the process may refer to. Many processes can open a file at once or by a single process only. It's all based on the file system and structure.
read()
It is used to obtain data from a file on the file system. It accepts three arguments in general:
The file descriptor of the file to be read could be used to identify it and open it using open() before reading.
wait()
In some systems, a process may have to wait for another process to complete its execution before proceeding. When a parent process makes a child process, the parent process execution is suspended until the child process is finished. The wait() system call is used to suspend the parent process. Once the child process has completed its execution, control is returned to the parent process.
write()
It is used to write data from a user buffer to a device like a file. This system call is one way for a program to generate data. It takes three arguments in general:
fork()
Processes generate clones of themselves using the fork() system call. It is one of the most common ways to create processes in operating systems. When a parent process spawns a child process, execution of the parent process is interrupted until the child process completes. Once the child process has completed its execution, control is returned to the parent process.
close()
It is used to end file system access. When this system call is invoked, it signifies that the program no longer requires the file, and the buffers are flushed, the file information is altered, and the file resources are de-allocated as a result.
exec()
When an executable file replaces an earlier executable file in an already executing process, this system function is invoked. As a new process is not built, the old process identification stays, but the new process replaces data, stack, data, head, etc.
exit()
The exit() is a system call that is used to end program execution. This call indicates that the thread execution is complete, which is especially useful in multi-threaded environments. The operating system reclaims resources spent by the process following the use of the exit() system function.
63 videos|7 docs|165 tests
|
1. How are system calls made? |
2. How do system calls work? |
3. What are some common types of system calls? |
4. Why are system calls important in computer science engineering (CSE)? |
5. Can system calls be directly accessed by user programs? |
63 videos|7 docs|165 tests
|
|
Explore Courses for Computer Science Engineering (CSE) exam
|