Week 10: Review
Week 1 – Syscalls
System calls are how Linux programs talk to the operating system. System calls look like function calls, but under the hood they are very different: instead of jumping to another place in your program, they switch out of your program and into the operating system. We used C for our examples in this course, but many languages have system APIs.
Weeks 2 & 3 – Filesystems
The filesystem is where Linux programs can read and write data that will persist indefinitely. Files are arrays of bytes; directories are listings of files (and possibly other directories). Linux permissions allow you to specify who can access a file and what they can do with it. Multiple processes can access the same file at once; use file locks or lock down permissions to protect against data races and corruption.
open(2)– open a fileread(2)– read from a filewrite(2)– write to a filelseek(2)– change read/write positionclose(2)– close a filestat(2)– get file metadatachmod(2)– change file permissionsmkdir(2)– create a directoryopendir(3)– open a directoryreaddir(3)– read a directory entryrename(2)– move or rename a fileunlink(2)– delete a filermdir(2)– delete a directoryflock(2)– lock a file
Week 4 – Process control
The process is the basic unit of running code on Linux. Processes are identified by PIDs, and run as a particular user and group. You create a new process with fork and start running a new program with execve. Every process has a parent, and parents can wait for their children to exit.
getpid(2)– get process IDgetppid(2)– get parent process IDgetuid(2)– get real user IDgetgid(2)– get real group IDgeteuid(2)– get effective user IDgetegid(2)– get effective group IDfork(2)– split into parent and child processexecve(2)– become a different programwaitpid(2)– wait for child to exit_exit(2)/exit(3)– exit the process
Week 5 – Interprocess communication
Interprocess communication refers to the various mechanisms for processes to communicate with each other. Pipes are a simple way for parent and child processes to pass data to each other. Shared memory lets (potentially unrelated) processes share data structures in memory, with access synchronized by semaphores.
pipe2(2)– create a pipeshm_open(3)– open a shared memory objectshm_unlink(3)– delete a shared memory objectmmap(2)– map a (shared) memory regionsem_open(3)– open a semaphoresem_wait(3)– wait on a semaphoresem_post(3)– release a semaphoresem_unlink(3)– delete a semaphore
Week 6 – Networking
The Linux socket API is used both for networking (talking to the external world) and as a form of IPC. Servers use bind, listen, and accept to handle incoming connections, while clients use connect to talk to the outside world. Sockets are file descriptors and can use the regular file I/O system calls, though specialized APIs like send and recv also exist.
socket(2)– create a network socketgetaddrinfo(3)– create an addressbind(2)– bind a server to a socketlisten(2)– listen for new connectionsaccept(2)– accept a new connectionconnect(2)– connect as clientsend(2)– send data on a socketrecv(2)– receive data on a socket
Week 7 – Multithreading
Multithreading lets different parts of the same program run concurrently (and possibly in parallel). The syscalls for multithreading are too low-level for regular use; applications use the pthreads interface instead. Mutexes and read-write locks let multiple threads synchronize with each other.
clone(2)– create a thread (low-level)pthread_create(3)– create a threadpthread_join(3)– wait for a threadpthread_exit(3)– exit a threadpthread_mutex_init(3)– create a mutexpthread_mutex_lock(3)– lock a mutexpthread_mutex_unlock(3)– unlock a mutexpthread_mutex_destroy(3)– delete a mutexpthread_rwlock_init(3)– create a read/write lockpthread_rwlock_rdlock(3)– lock a read/write lock for readingpthread_rwlock_wrlock(3)– lock a read/write lock for writingpthread_rwlock_unlock(3)– unlock a read/write lock for writingpthread_rwlock_destroy(3)– delete a read/write lock
Week 8 – Signals
Signals are a wait to asynchronously notify a process of an interesting event. Signals can be ignored or handled by a callback function. Processes can mask signals – temporarily blocking. Like multithreading, signals are a form of concurrent execution, and are tricky to get right.
kill(2)– send a signalsigaction(2)– set action for signalsigprocmask(2)– get or set signal maskpause(2)– wait for any signalsigwait(2)– wait for a signalsigsuspend(2)– set mask and wait for a signal
Week 9 – Advanced I/O
Some programs need to read and write from multiple devices at once. Linux provides the O_NONBLOCK flag, the epoll family of system calls, and most recently the io_uring subsystem to do so conveniently and efficiently.