ubuntu 14.04.1 LTS父进程终止,子进程没有被init(1)进程领养

fork一个子进程,在子进程中打印父进程终止前后的PPID:
按照正常的理解,首先会打印父进程的PID,然后会打印init(PID=1)。因为子进程转为孤儿进程被init进程收养。
 
 
<pre name="code" class="cpp">#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(void)
{
    pid_t pid;

    pid = fork();
    if(pid == 0)
    {
        while(1)
        {
            printf("I am child exit,my parent %d\n",getppid());
            sleep(1);
        }
    }
    else if(pid > 0)
    {
        printf("I am parent\n");
        sleep(1);
    }
    else
    {
        perror("fork");
        exit(1);
    }

    return 0;
}

 
 
在Red Hat Enterprise Linux Server release 6.4 (Santiago)下运行的结果为:
<img src="http://img.blog.csdn.net/20150123124633359?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGlmYW4xMzE0NTIx/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />

在ubuntu 14.04.1 LTS下运行的结果为:

ubuntu 14.04.1 LTS父进程终止,子进程没有被init(1)进程领养_第1张图片

很疑惑为什么不是被init(1)进程领养。



在ubuntu下PID为2978的进程为init --user


查了些资料有了些头绪:

Ubuntu使用Upstart作为默认init系统.


Upstart can now run as a normal user process (whose PID is not 1) both as root or as a non-privileged user by passing the --user option. This feature is employed to supervise a user's desktop session (technically those sessions listed in /etc/upstart-xsessions). The Session Init is started /etc/X11/Xsession.d/99upstart which starts a Session Init for a user.

Upstart is now used to supervise a user's desktop session. To see details of the running Upstart session, either echo $UPSTART_SESSION (用这个命令可以查看本机--user的属性)to see the D-Bus address the Session Init process is listening to.

--user (Running a Session Init)
Runs Upstart as a Session Init.

你可能感兴趣的:(upstart,孤儿进程)