如何让父进程显示子进程的PID而不是值变量?

时间:2013-12-15 20:59:16

标签: linux process pid

在linux中如何让父进程显示子进程的PID而不是值变量?

1 个答案:

答案 0 :(得分:0)

你获得孩子PID的机会就在你分叉的时候。

的Python:

import os

child_pid = os.fork()
if child_pid == 0:
    print "This is the child, my pid is", os.getpid()
else:
    print "This is the parent, my child pid is", child_pid

C:

pid_t child_pid = fork();
if (child_pid == 0) {
    printf("This is the child, my pid is %d\n", getpid());
}
else {
    printf("This is the parent, my child pid is %d\n", child_pid);
}