# System Calls **System calls** are how the kernel interacts with the hardware. They are kernel entry points. Want to open a file? Call ``open`` and then call ``read`` or ``write``. Want to do some networking? Call ``connect`` to open a new connection and ``send`` to send something, ``recv`` to receive. So, system calls are the **operating system’s universal API**. Some (very little amount of) system calls: ``open`` - opens a file (returns a file descriptor) ``read`` - read bytes from fd (file, socket) ``write`` - write to fd - ``stat`` - read file statistics ``ioctl`` - set I/O properties ``connect`` - connect to an IP address ``accept`` - accept a network connection ``sendto/recvfrom`` - using network: send to X, receive from X ``socket`` - open network connections - ``fork`` - creates new process ``mmap`` - map a file to the process memory address space (allocate memory for a file) ``munmap`` - unmap the memory ``brk`` - extend the heap pointer (allocate memory) ``exec`` or ``execve`` - execute a new program (infect forked process) System calls let userland programs interact with the OS by switching from user space to kernel space using software interrupts. Fork() ------ This system call is used to create processes identical to their parents. Every time a process requires a child (e.g the shell) it forks itself and, if required, calls execve to replace the child process with a new one. [The fork() System Call](https://www.csl.mtu.edu/cs4411.ck/www/NOTES/process/fork/create.html) -> great explainer on forking with C example Links ----- * https://www.man7.org/linux/man-pages/man2/syscalls.2.html contains a lot of information I should go through some time.