Chapter 2: Processes | 🗒️ Ben's Notes
The process abstraction creates a tradeoff between protection and efficiency: communication is easier within processes, but harder between processes. In UNIX-based systems, the primary way to create new processes is to fork an existing process. This creates a child process with a single thread, and copies all code and resources available to the parent process at that point in time. Forking can be done with the C library function pid_t fork(). fork returns a process ID (pid) that allows us to identify which process is currently running: When fork is called, the following operations are carried out by the kernel: Don’t fork in a multithreaded process! Fork only copies one thread, so any other threads will vanish. (The exception to this rule is if exec is called within the child process, since this replaces the entire process anyways and the destruction of threads is desired.) Parent and child processes work with entirely separate address spaces. For example, take the code below: Even tho
The process abstraction creates a tradeoff between protection and efficiency: communication is easier within processes, but harder between processes. In UNIX-based systems, the primary way to create new processes is to fork an existing process. This creates a child process with a single thread, and copies all code and resources available to the parent process at that point in time. Forking can be done with the C library function pid_t fork(). fork returns a process ID (pid) that allows us to identify which process is currently running: When fork is called, the following operations are carried
Explore this link on the map →