Processes & Signals Flashcards
What’s a process?
- An implementation of the abstract machine concept
- A running instance of an executable, invoked by a user
– Can have multiple independent processes of the same executable - A schedulable entity, on the CPU
Also called Task or Job sometimes
How does the Process address space looks like?
מכתובות נמוכות לגבוהות:
text segment אחריו data segment אחר כך אולי עוד כל מיני סגמנטים ואז הערימה ובסוף בכתובות הגבוהות המחסנית.
המחסנית גדלה כלפי מטה והערימה כלפי מעלה.
Can a process access its own PCB?
No. because the pcb is in kernel space.
What happens to a process after it dies?
It becomes a zombie
What syscall a parent uses to clear zombie children from the system?
wait
What flag is needed for wait to not block the parent?
WNOHANG
What are the steps of fork?
- fork() initializes a new PCB
- Creates a complete copy of parents space in the child.
- Return twice:
– At the parent, with pid>0
– At the child, with pid=0
What are the steps of exec invokation?
– Stops the execution of the invoking process
– Loads the executable ‘programPath’
– Starts ‘programPath’, with ‘argv’ as its argv
– Never returns (unless fails)
– Replaces the new process; doesn’t create a new process
• In particular, PID and PPID are the same before/after exec*()
Who wait()-s upon an “orphan” process?
In linux, Init.
If a parent process terminates, then its zombie children (if any) are
adopted by init
What are signals & signal handlers?
Signal = notification “sent” to a process
– To asynchronously notify it that some event occurred
• Upon receiving a signal
– The process stops whatever it is doing & handles it
• Default signal handling action
– Either die or ignore (depends on the type of the signal)
What does the kill -s n pid utility does?
sends signal number n to process pid.
What 2 signals the process can’t ignore?
– SIGKILL = terminate the receiving process
– SIGSTOP = suspend the receiving process
Explain the difference between signal and interrupt by following criteria:
- When do they occur?
- Who (i) triggers them and (ii) defines their semantics
- Who handles them, who blocks them
- – Both can be asynchronous
– But signals are invoked only when returning from kernel to user, and
interrupts can really fire anytime - – Interrupts: hardware – devices (async) or cores (sync)
– Signals: software (OS) – HW is unaware - – Interrupts: OS
– Signals: processes
How is blocking signals implemented?
– The PCB maintains a set of currently blocked signals
– Which can be manipulated by users via the following syscall
• int sigprocmask(int how, const sigset_t *set, sigset_t *oldset)
– ‘how’ = SIG_BLOCK (+=), SIG_UNBLOCK (-=), SIG_SETMASK (=)
– ‘set’ can be maipulated with sigset ops sigetmptyset(sigset_t *set),
sigfillset(sigset_t *), sigaddset(sigset_t *set, int signum),
sigismember(sigset_t *set, int signum)