0
在linux中我怎樣才能讓父進程顯示子進程的PID而不是值變量?如何讓父進程顯示PID的子代替值變量?
在linux中我怎樣才能讓父進程顯示子進程的PID而不是值變量?如何讓父進程顯示PID的子代替值變量?
當你分叉時,你得到孩子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);
}
在哪種語言? 'bash'或'C'? –
@BasileStarynkevitch C請 – mrplow911