- #include <stdio.h>
-
#include <sys/types.h>
-
#include <unistd.h>
-
int glob = 6;
-
int main()
-
{
-
int var;
-
pid_t pid;
-
var == 88;
-
printf("before vfork\n");
-
if((pid = vfork()) < 0){
-
perror("vfork error\n");
-
}else if (pid == 0){
-
glob++;
-
var++;
-
exit(0);
-
}
-
sleep(1);
-
printf("pid=%d, glob=%d, var=%d\n", getpid(), glob, var);
-
exit(0);
- }
[root@localhost tast]# ./4test
before vfork
pid=29821, glob=7, var=3722433
看起来exit没有关闭标准I/O流!!!