System calls provide an interface to the services made available by an operating system.
User mode
Kernel mode
Most programs run in user mode, but some might need access to resources. Thus, the program calls for requests, and these are called system calls.
| System Call | Purpose |
|---|---|
| open() | Opens a file or device. |
| read() | Reads data from a file or device. |
| write() | Writes data to a file or device. |
| close() | Closes a file or device. |
| fork() | Creates a new process (a child). |
| exec() | Replaces the current process with a new program. |
| socket() | Creates a network socket for communication. |
| bind() | Associates a socket with an address/port |
| listen() | Prepares a socket to accept connections. |
| accept() | Accepts an incoming connection on a socket. |
A system call table is essentially a lookup table in the kernel for the functions. It maps syscall numbers to to their corresponding functions, and jumps to the function address when called.
Here’s what a system call table on a Linux machine might look like:
0 common read sys_read
1 common write sys_write
2 common open sys_open