【发布时间】:2013-12-15 20:59:15
【问题描述】:
在linux中如何让父进程显示子进程的PID而不是value变量?
【问题讨论】:
-
使用哪种语言?
bash或C? -
@BasileStarynkevitch C 请
在linux中如何让父进程显示子进程的PID而不是value变量?
【问题讨论】:
bash 或 C ?
你获得子 PID 的机会是在你 fork 的时候。
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);
}
【讨论】: