System calls
System calls allow user programs to communicate with the operating system. Every OS has a calling convention that defines how parameters are passed to the function. On Unix, many syscalls are similar to shell commands.
File descriptors #
File descriptor: integer pointing to a file to use in syscalls
A few important standard file descriptors (used by shells and in IPC) are:
- Standard input (stdin): 0
- Standard ouput (stdout): 1
- Standard error (stderr): 2
Common Unix syscalls #
read
- reads bytes a file descriptorwrite
- writes bytes to a file descriptorseek
- repositions read/write file offsetfork
- crates a child process identical to the parentexec
- replaces the process with a new processkill
- sends a signal to a processsignal
- setup a signal handler for the process
Common Unix Signals #
Signals can be seen as a software version of interrupts.
SIGINT
(2): Interrupt signal, send by CTRL+C in the terminal.SIGKILL
(9): Immediately kills a process, cannot be caught or ignoredSIGTERM
(15): Termination signalSIGSTOP
(19) andSIGCONT
(18): signals to stop and continue a process, respectively. On the terminal CTRL+Z sendsSIGSTOP
and thefg
builtin command resumes it.SIGSEGV
(11): Segmentation fault, often caused by bugs in C programs :)SIGCHLD
(17): Child stopped or terminated