1 #include "apue.h" 2 3 int globvar = 6; 4 char buf[] = "a write to stdout "; 5 6 7 int main(void) 8 { 9 int var; 10 pid_t pid; 11 12 var = 88; 13 if(write(STDOUT_FILENO,buf,sizeof(buf)-1) != sizeof(buf) -1) 14 err_sys("write error "); 15 printf("before fork "); 16 17 if((pid = fork()) < 0){ 18 err_sys("fork error"); 19 }else if(pid == 0){ 20 globvar++; 21 var++; 22 }else{ 23 sleep(2); 24 } 25 printf("pid = %ld,glob = %d,var = %d ",(long)getpid(),globvar,var); 26 27 exit(0); 28 }