System calls provides a layer between hardware and the user space.
- Provides abstracted hardware interface for user space
- system calls ensure security and stability
- single common layer between user space and rest of the system
System calls usually accessed via function calls.
- call to the printf () function //through a function call
- Access to the C library functions
- access the kernel and execute the write() function to write on to the screen
- System calls returns a long variable for success, negative value indicates error
- Each system call is assigned a syscall number defined in sys_call_table in entry.S
- system calls are faster than many other operating systems
Example System Calls
asmlinkage long sys_getpid)
Interrupts the execution of the program until the process is reactivated by a signal.
asmlinkage int sys_pause(void)
current-> state = TASK_INTERRUPTIBLE;
Complex System Calls
The fork() function shall create a new process. The new process (child process) shall be an exact copy of the calling process (parent process) except as detailed below.
- The child process shall have a unique process ID.
- The child process shall have a different parent process ID, which shall be the process ID of the calling process.
- The child process shall have its own copy of the parent’s file descriptors. Each of the child’s file descriptors shall refer to the same open file description with the corresponding file descriptor of the parent.
create new process; share virtual memory
The vfork() function has the same effect as fork(), except that the behavior is undefined if the process created by vfork() either modifies any data other than a variable of type pid_t used to store the return value from vfork(), or returns from the function in which vfork() was called, or calls any other function before successfully calling exit() or one of the exec family of functions.
clone() is a system call on the Linux kernel related to multithreading works similar like fork() but shares the information with the calling process.