More explanation
This commit is contained in:
parent
9ef65e0f4c
commit
5fbd7abd26
1 changed files with 14 additions and 1 deletions
15
main.c
15
main.c
|
@ -94,6 +94,9 @@ int main(int argc, const char** argv)
|
|||
|
||||
if (pid != 0)
|
||||
{
|
||||
/// Head process
|
||||
// Wait for the init process in the PID namespace to terminate and forward its exit code.
|
||||
// Also forward SIGTERM signals towards that init process.
|
||||
|
||||
// Setup signal handler to forward SIGTERM
|
||||
pid_child = pid;
|
||||
|
@ -122,7 +125,17 @@ int main(int argc, const char** argv)
|
|||
pid = fork();
|
||||
if (pid != 0)
|
||||
{
|
||||
// Init process wait for anything and exit if first child exits.
|
||||
/// Init process
|
||||
// This part of the program runs as first process in the pid namespace
|
||||
// When this terminates then Linux terminates all remaining processes
|
||||
// in the PID namespace. As we want this to happen when our first child
|
||||
// terminates, we wait for our first child to terminate before terminating
|
||||
// ourselves.
|
||||
// As first process in the PID namespace, this also functions as adopting parent
|
||||
// for orphaned processes in the PID namespace and therefore has to wait for
|
||||
// any child process and then check if the a child process that has terminated
|
||||
// is the one we were waiting for.
|
||||
|
||||
pid_t first_child = pid;
|
||||
pid_t exited_child;
|
||||
int child_status;
|
||||
|
|
Loading…
Reference in a new issue