graphene icon indicating copy to clipboard operation
graphene copied to clipboard

[LibOS] Child processes are not informed about parent death

Open boryspoplawski opened this issue 5 years ago • 2 comments

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 avatar Dec 08 '20 12:12 boryspoplawski

@boryspoplawski What is the status of this issue?

dimakuv avatar Jul 22 '21 09:07 dimakuv

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.

boryspoplawski avatar Jul 22 '21 11:07 boryspoplawski