To transition from the user space to kernel space, the user/compiler uses the system call. System calls are the entry points into the kernel, enabling necessary actions that are to be performed on kernel on behalf of processes. The system call changes the processor state from user mode to kernel mode, granting the CPU access to protected kernel memory. One example of utilizing system calls is through dynamic memory allocators like malloc() and realloc(), which dynamically allocate memory. It’s important to note that while malloc() and realloc() are library functions, the underlying system calls they rely on are sbrk() and brk().
Let’s delve into one of the system call used in process management:
π¬π²π¬πππ¦(): This system call allows a calling program to execute a shell command. It has the following syntax:
π’π§π π¬π²π¬πππ¦(ππ¨π§π¬π ππ‘ππ« *ππ¨π¦π¦ππ§π);
Internally, system() uses fork() to create a child process, which then executes the specified shell command using execl(). The command is typically executed by calling “/ππ’π§/π¬π‘ -π”. The return value of system() is the termination status of the child shell used to execute the command.
Function called by system() -> excel(β/bin/shβ,βshβ,β-cβ,command,(char *) NULL);
Inputs to system() can be given at compile time, load time, execution time . The delimiter β;β can be used to give multiple commands. System() is main back drop is its inefficiency. When system() is used, a minimum of 2 processes are created along with it, one for shell and one more for command. It internally uses other process management system calls such as clone(), wait(),rt_sigaction() etc.
ππ₯π¨π§π(): This system call creates a new process, known as a child process, which shares the same memory space as the parent process. It provides a flexible way to create processes with various levels of sharing between the parent and child processes.
π°ππ’π(): This system call suspends the execution of the calling process until one of its child processes terminates. It allows the parent process to wait for the termination of specific child processes or any child process.
π«π_π¬π’π ππππ’π¨π§(): This system call is used to set up a signal handler for a specified signal. It allows processes to handle various signals asynchronously, enabling them to respond appropriately to events such as interrupts or exceptional conditions.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
An Article by: Yashwanth Naidu Tikkisetty
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
