System calls is an important part of Operating System and most of the student gets confused while studying this topic. But don't worry I will explain you about system calls in from very beginner level.
So let's get stated, shall we:
What is a System Call?
System call is basically an interface by which user programs can request to access functionalities of kernel mode from OS. System calls provide functionalities to the user programs via APIs (Application Program Interface).
So you can say whenever user wants to access resources of kernel a system call must be used.
Working of a System call
- Initially the processes are executed in the user mode until a system call is interrupted.
- When a system call is interrupted it is executed in the kernel mode on a priority basis.
- When the work of system call is done the control returns to user mode again.
- Then the execution starts in user mode from where it was paused.
- System calls are needed for creation, deletion or opening of files in the file system.
- System calls are needed for creation or management of new processes.
- System calls are needed to create connection in a network for sending or receiving data.
- System calls are needed to request access to various hardware devices like mouse, printer etc.
Process Control System Calls
These system calls are responsible for performing functions on processes like:
1. End and abort
2. Load and execute
3. Create Process and terminate Process.
4. Wait and Signal event
5. Allocate and free memory.
File Management System Calls
These system calls perform functions on files like:
1. create a file
2. read a file
3. open or close a file
4. read, write and reposition
5. get or set file attribute.
Device Management System Calls
These system calls are responsible for performing actions on device like:
1. request and release device
2. attach/detach device
3. set or get a device.
Communication System Calls
These system calls are used mainly for interprocess communication. It has the following functions:
1. Create or terminate connections
2. send/receive message
3. Helps OS to transfer status information
Information Maintenance System Calls
These system calls transfer of information between OS and user program. It has the following functions:
1. get/set date or time
2. get process and device attribute.
Some important system calls
fork()
fork system call is used to create a process.When a process makes a call to fork then a clone or child copy of that process is made. So, now there are 2 processes, one being the parent process and other being the child process.
We will discuss about fork in more detail in upcoming lectures.
exec()
exec system call creates a new process. But the difference between fork and exec is that fork create a child of a parent process while exec replaces a process with a new process.
We will discuss about exec in more detail in upcoming lectures.
kill()
kill system call is used to send a signal to a process that urges a process to terminate.
exit()
exit system call is used to terminate program execution.