Ubuntu下调用fork()函数创建子进程

#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
int main()
{
 int pid;
 printf("The pid before fork:%d\n",getpid());
 pid= fork();
 if(pid<0)
 printf("error!!!\n");
 else if(pid ==0)
 printf("I am the child,my pid is:%d\n ",getpid());
 else 
 printf("I am the father,my pid is:%d\n",getpid()); 
 printf("Hello Fork!\n");
 return 0;}

猜你喜欢

转载自blog.csdn.net/qq_40747974/article/details/80955375
今日推荐