OS 01/29
Process
What if parent process killed before child?
Parent process terminates before child, child will change its parent to the initial process. It has ppid=1. (Orphan process get adopted by process no.1) Init process always runs, and it’s by default the parent of all processes.
What if child process terminates first but parent never calls waitpid?
When a process terminates, kernel keeps around struct task_struct, process will stay in system. When parent calls waitpid, will return child process status. Until then, this zombie process will be harvested.
If the parent didn’t call waitpid specifically, after parent died, zombie child process will be adopted by init process, which always calls waitpid. So zombie process can be harvested.
Signal
Interprocess communication (IPC). One way for process communicate to another process.
Ex. Ctrl+C sends a signal to process, call kill function (signal number 2)
How to catch signal
Call signal function to register a signal handler.signnal(SIGINT, &sig_int) == SIG_ERR
When a signal happens, immediately jumps to signal handler (sig_int function).