系统编程之进程管理 fork—pid

来源:互联网 发布:日韩和欧美护肤知乎 编辑:程序博客网 时间:2024/04/18 21:20
#include<unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <math.h>
int main(void )
{
    pid_t child ;
    /*创建子进程*/
    if ((child=fork())== -1)
    {
        printf("Fork Error: %s\n",strerror(errno));
        exit(1);
    }
    else if(child == 0) //子进程
    {
        printf("I am the child :%d\n",getpid());
        exit(0);
     }
      else //父进程
    {
        printf("I am the father:%d\n",getpid());
        return 0;
    }
}
原创粉丝点击