System Calls

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.

for example

  1. call to the printf () function   //through a function call
  2. Access to the C library functions
  3. 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

//Example1

asmlinkage long sys_getpid)

{

return current->tgid;

}

Pause:

Interrupts the execution of the program until the process is reactivated by a signal.

asmlinkage int sys_pause(void)

{

current-> state = TASK_INTERRUPTIBLE;

schedule();

return ERESTARTNOHAND;

}

Complex System Calls

fork()

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.

SYNTAX:

#include <unistd.h>

pid_t fork(void);

  • 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.

vfork()

create new process; share virtual memory

#include <unistd.h>

pid_t vfork(void);

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()

clone() is a system call on the Linux kernel related to multithreading works similar like fork() but shares the information with the calling process.

Comments

Popular Posts