什么杀死了父进程?

What kills the parent process?

什么结束了这段代码中的父进程?我看到他没有离开任何地方...... 我的一个朋友说父级不是 ended/kiled,代码只是在最后一个出口 (0) 处停止。如果是这种情况,那么是什么将父进程从睡眠中唤醒呢?提前谢谢你

adghtesd

程序的结果:

    parent: I'm the parent
    child: I'm the child
    child: I'm exiting
    parent: child process (PID=1919) exited with value 123
    parent: exiting
    test

来自 this POSIX reference on sleep:

If sleep() returns because the requested time has elapsed, the value returned shall be 0. If sleep() returns due to delivery of a signal, the return value shall be the "unslept" amount (the requested time minus the time actually slept) in seconds.

发生在你身上的是,当父进程收到SIGCHLD信号时,导致sleep函数中断,而父进程在sleep调用后继续。

如果你想睡满,你需要检查sleep returns,然后循环调用sleep,直到它returns [=18] =].