pid_t pid;if((pid =fork())<0){perror(“fork”);return-1;}elseif(pid ==0){printf(“child process : my pid is %d
”,getpid());}else{printf(“parent process : my pid is %d
”,getpid());}
#include#includeintmain(void){printf(“this process will exit
”);//标准输出是行缓冲,字符串末尾有换行符,此时字符串写到了标准输出的缓冲区里,遇到了换行符,会刷新流缓冲区,并输出printf(“this is the end”);//标准输出是行缓冲,字符串末尾没有换行符,此时只是将字符串写到了标准输出的缓冲区里,并没有输出exit(0);//程序结束时会刷新流缓冲区,将缓冲区中的内容输出到终端printf(“never be displayed”);}this process will exitlinux@linux:~/test/process$ vi a.c
linux@linux:~/test/process$ gcc a.c
linux@linux:~/test/process$ ./a.out
this process will exit
this is the endlinux@linux:~/test/process$
进程结束_exit()示例
#include#includeintmain(int argc,constchar*argv[]){printf(“this process will exit
”);//标准输出是行缓冲,字符串末尾有换行符,此时字符串写到了标准输出的缓冲区里,遇到了换行符,会刷新流缓冲区,并输出printf(“this is the end”);//标准输出是行缓冲,字符串末尾没有换行符,此时只是将字符串写到了标准输出的缓冲区里,并没有输出exit(0);//程序结束时不会刷新流缓冲区printf("never be displayed");return0;}this is the endlinux@linux:~/test/process$ vi a.c
linux@linux:~/test/process$ gcc a.c
linux@linux:~/test/process$ ./a.out
this process will exit