System Calls in OS
System Calls in OS
System call is the special function that is used by the process to request action
from the operating system which cannot be carried out by normal
function. System calls provide the interface between the process and the
operating system.
Process Control
File Management
Device Management
Information Maintenance
Communication
CreateProcess()
WaitForSingleObject()
CreateFile()
ReadFile()
CloseHandle()
SetConsoleMode()
WriteConsole()
GetCurrentProcessID()
Sleep()
CreatePipe()
Communication CreateFileMapping()
MapViewOfFile()
As we can see in the diagram, initially, the process pushes the parameter
onto the stack.
After that, the read routine from the library is called, which puts the
system call code (unique code for each system call is assigned) into the
register.
Trap instruction is used which causes the transfer of control from user
mode to kernel mode.
Kernel reads the system call code present in the register and finds out that
the system call is read, so the system call handler executes the read
system call.
After the execution of the read system call, the transfer is given back to
the user mode.
The library routine (Library routine is nothing but the line of codes that
forms the library and the functions that can be called by the process so
that we don't need to write the function every time. e.g... max function) in
user mode returns the output to the process which called it.
On receiving the output, the process continues to execute the next
instruction.
Note: Trap is the kind of interrupt that is synchronous to the process for
executing the functionality.
1. wait(): There are scenarios where the current process needs to wait for
another process to complete the task. So to wait in this scenario, wait()
system call is used.
2. fork(): This system call creates the copy of the process that has called it.
The one which has called fork is called the parent process and the newly
created copy is called the child process.
3. exec(): This system call is called when the running process wants to
execute another executable file. The process id remains the same while
the other resources used by the process are replaced by the newly created
process.
4. kill(): Sometimes while working, we require to terminate a certain
process. So kill system call is called which sends the termination signal to
the process.
5. exit(): When we are actually required to terminate the program, an exit
system call is used. The resources that are occupied by the process are
released after invoking the exit system call.
Conclusion