2.3创建进程函数fork的使用补充(第二阶段)
代码展示
#include<stdio.h>
#include<sys/types.h>
#include<unistd.h>
int main()
{
pid_t pid;
pid_t pid2;
pid_t retpid;
pid = getpid();
printf("before fork:pid = %d\n",pid);//子进程
retpid = fork();
pid2 = getpid();
printf("after fork:pid = %d\n",pid2);//父进程
if(pid == pid2){
printf("this is father print,retpid:%d\n",retpid);
}else{
printf("this is child print,retpid:%d,child pid = %d\n",retpid,getpid());
}
return 0;
}