Chapter 5 - Interlude: Process API Flashcards
what does fork() do - system call
It copies the calling process, creating a new process (the child)
What does the new (child) process get after fork()?
Its own address space, registers, and program counter.
What does fork() return to the parent process?
The PID (Process ID) of the child – a positive value
Why can output vary when using fork()?
Because execution is non-deterministic – whether the parent or child runs first depends on the CPU scheduler
What does fork() return to the child process? - and what return if error
0 - negative value
What does the CPU scheduler do?
It decides which process gets to run and when
What happens when a parent calls wait()?
It blocks (pauses) until the child process terminates, then returns the child’s PID.
How does wait() ensure deterministic output?
Whether the child runs first or second, the parent blocks at wait(), so the child always prints before the parent.
What does exec() do?
It replaces the current process with a new program — code, data, etc., but keeps the same PID.
How does redirection work in a shell?
Through manipulation of file descriptors before calling exec()
What is a signal?
A message sent to a process to notify it of an event.
What can signals do to a process?
kill, pause, resume, trigger custom behaviour