2013-12-15 67 views

回答

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); 
}