#include<stdio.h>#include<sys/types.h>#include<unistd.h>intmain(){
pid_t pid;
pid =getpid();fork();printf("my pid is %d , current pro id %d\n",pid,getpid());while(1);return0;}
#include<stdio.h>#include<sys/types.h>#include<unistd.h>intmain(){
pid_t pid;
pid =getpid();fork();if(pid ==getpid()){printf("this is father print\n");}elae{printf("this is child print,child pid = %d\n",getpid());}return0;}
#include<stdio.h>#include<sys/types.h>#include<unistd.h>intmain(){
pid_t pid;
pid_t pid2;;
pid =getpid();printf("before fork : pid = %d\n",pid);fork();
pid2 =getpid();printf("after fork :pid = %d\n",pid2);if(pid == pid2){printf("this is father print\n");}else{printf("this is child print,child pid = %d\n",getpid());}return0;}
#include<stdio.h>#include<sys/types.h>#include<unistd.h>intmain(){
pid_t pid;printf("father: id =%d\n",getpid());
pid =fork();//fork返回值if(pid >0){//返回值大于0的整数,即父进程printf("this is father print\n");}elseif(pid ==0){//返回对于0,即为子进程printf("this is child print,child pid = %d\n",getpid());}return0;}