Made with ScholarlyTurn your own notes into slides like these
Shared by khulumani sibanda
System calls are the controlled boundary between Unix/Linux application code and operating-system services. A program requests a service, the kernel validates the request and performs privileged work, then returns a value or error to user mode (p. 1). The section’s process-control route is: create with fork(), transform with exec(), coordinate with wait()/waitpid(), respond to asynchronous events with signals and handlers, and diagnose failures with status information, errno, and tracing (p. 1).
The interface is deliberately narrow: user mode → system call → kernel mode → return. Application code makes a controlled entry, the kernel provides the privileged service, and the result returns as a value or error (p. 2). The slides specifically distinguish a library wrapper such as printf() from the kernel interface; write() is presented as the lower-level file-descriptor operation (p. 2).
A program is an executable file containing instructions and static data. A process is “active execution with its own state, PID, registers, stack, heap, open descriptors, and scheduling/security context” (p. 3). Thus, one program can become multiple independent process instances. The simplified memory layout places program code and global data at lower addresses, the heap above them, unused address space in the middle, and the stack at higher addresses (p. 3).
fork() creates two execution flowsfork() duplicates the process path: after the call, parent and child both continue from the return point, following the same code path but having distinct PIDs (p. 4). The return value identifies the branch:
fork() == 0: this execution is the child.fork() > 0: this execution is the parent, and the value is the child PID.fork() == -1: the call failed (p. 4).The key exam distinction is that fork() creates another process flow; it does not merely call the same function twice in one process.
exec() replaces rather than createsexec() changes what the calling process runs; it does not create a new process. In the slide’s example, PID 418 changes from a shell process image to an ls process image after execlp("ls", "ls", "-l", NULL) (p. 5). A successful exec() normally does not return. The standard pattern shown is: fork() creates the child, the child calls exec(), and the parent either continues or waits (p. 5).
The lifecycle is: child runs → child terminates → status is stored → parent waits/reaps (p. 6). A parent must collect child state; otherwise a terminated child may remain a zombie. A zombie has terminated, no longer executes, but still consumes process-table resources because its parent has not collected its status (p. 6). An orphan is still running after its original parent terminates; the operating system adopts or re-parents it so it can eventually be reaped (p. 6).
Signals are notifications that arrive outside normal control flow. The source lists terminal interrupts, child state changes, illegal memory access, timers, and another process as possible causes (p. 7). Signal handling follows the sequence event occurs → signal delivered → disposition selected (p. 7). The listed signals are:
SIGINT: terminal interrupt, commonly Ctrl+C.SIGTERM: request for process termination.SIGKILL: forceful termination; cannot be caught or ignored.SIGSTOP: stops the process; cannot be caught or ignored.SIGCHLD: child process changed state.SIGSEGV: invalid memory access (p. 7).sigaction() and handlersThe three signal dispositions are default action, ignored action, and handler executes (p. 8). The preferred interface is sigaction(), which the source describes as offering more predictable and flexible semantics than the simpler signal() (p. 8). Handlers should be simple: record the event and let ordinary code perform complex work. The minimal pattern shown checks for SIGINT and uses write(STDOUT_FILENO, "SIGINT received\\n", 16). The slide warns against complex non-async-signal-safe library work inside handlers (p. 8).
fork() can print twiceFor the code:
fork(); printf("Hello\n");
both the parent and child continue from the return point, so the printf() statement can execute in both processes. As a result, “Hello” may appear twice (p. 4).
The shell is the section’s integrated practical example. Its process-control sequence is:
fork().exec().waitpid().This example ties together creation, replacement, coordination, notification, and diagnosis.
exec() with a stable PIDThe slide’s before/after example uses PID 418. Before execlp("ls", "ls", "-l", NULL), PID 418 contains the shell process image; after a successful exec(), the same PID 418 contains the ls process image (p. 5). The process identity is therefore not replaced by a new PID in this example; what it runs is replaced.
The essential fork() decision rule is expressed through its return values:
These return values are the branch that lets parent and child take different paths after continuing from the same return point (p. 4).
fork() creates the additional process flow, while exec() changes the child’s process image without creating another process (pp. 4-5).wait() or waitpid() to collect the child’s stored termination status and prevent an unreaped terminated child from remaining a zombie (p. 6).sigaction() selects predictable behavior, while handlers should only perform simple work (pp. 7-8).waitpid(), incorrect signal handling, deadlocks, and unexpected scheduling (pp. 9-10).printf() as a library wrapper from write() as the lower-level file-descriptor operation (p. 2).fork(), interpret all three return cases, and explain why the Hello example may print twice (p. 4).fork() from exec() using the PID 418 shell-to-ls example: creation versus process-image replacement, and why successful exec() normally does not return (p. 5).SIGKILL and SIGSTOP (p. 7).sigaction(), and why handlers should avoid complex non-async-signal-safe library work (p. 8).pid == -1; cause → perror() or errno; child termination mode → WIFEXITED, WEXITSTATUS, WIFSIGNALED, and WTERMSIG; actual execution sequence → system-call tracing or a debugger (p. 9).fork(), and the invariant that an operation must never be assumed to have succeeded (p. 10).Make from this