#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <errno.h>
int main()
{
pid_t child;
/*创建子进程*/
if((child=fork())==-1)
{
printf("Fork Error:%s\n",strerror(errno));
exit(1);
}
else
if (child == 0) //child
{
printf("the child process is running \n");
sleep(1);
printf("I am the chil: %d\n",getpid());
exit(0);
}
else //parament
{
wait(NULL);//等到任一子进程退出,父进程才会运行
// waitpid(child,NULL,0); //等待特定的进程
printf("the father process starts run\n");
printf("I am the father: %d\n",getpid());
return 0;
}
}