|
|
我想在fork之后,在子进程执行时,将该子进程的pid保留下来,用于回到父进程后使用。
int chd_pid;//
if ((pid = fork ()) < 0) {
perror ("fork");
exit (1);
} else if (pid == 0) { /* child process */
chd_pid = getpid();//这个值在退出子进程后,就为任意值了
int fd = open ("/dev/null", O_WRONLY);
if (fd < 0) {
perror ("open /dev/null");
} else {
if (dup2 (fd, 1) < 0 || dup2 (fd, 2)) {
perror ("dup2");
}
}
}
请问,我怎么样才能把那个chd_pid保留下来?
谢谢了! |
|