More explanation

This commit is contained in:
madmaurice 2021-01-15 20:22:22 +01:00
parent 9ef65e0f4c
commit 5fbd7abd26

15
main.c
View file

@ -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;