[LibOS] Child processes are not informed about parent death
Description of the problem
Child processes are not informed about parent death. There should be a policy of reparenting (probably to pid 1 inside Graphene instance).
Steps to reproduce
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>
int main(void) {
setbuf(stdout, NULL);
setbuf(stderr, NULL);
pid_t p = fork();
if (p < 0) {
err(1, "fork");
} else if (p == 0) {
p = fork();
if (p < 0) {
err(1, "fork in child");
} else if (p == 0) {
sleep(1);
printf("grand child: %d\n", getppid());
return 0;
}
return 0;
}
printf("my pid: %d\n", getpid());
if (wait(NULL) < 0) {
err(1, "wait");
}
sleep(2);
return 0;
}
Expected results
my pid: 1
grand child: 1
Actual results
my pid: 1
grand child: 2
@boryspoplawski What is the status of this issue?
Still present. Some more context from #2472 (which had an issue connected to this):
This made me realize that the current semantics are a bit off: a child releases it's pid on exit, yet it might still be a zombie in the parent. In a unlikely case that the parents does not wait for the child for a long time and pids overlap we could have a nasty conflict. The problem is that solving this is hard: we would need to make the parent own the pid of the child, but that would require "reparenting" in case the parent dies but the child is still alive. Such solution would also have some nasty consequences: Graphene pid 1 (which I guess would become the new parent) might not be expecting to have more children than it spawned (normal apps do not expect that, as init process is pretty special). Generally speaking: there is a problem and there is no good solution to it.