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

来源:互联网 发布:软件培训班好不好 编辑:程序博客网 时间:2024/05/01 22:06
#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()
{
    pid_t child ;
    /* 创建子进程*/
    if((child=vfork()) == -1)
    {
        printf("Fork Error :%s\n",strerror(errno));
        exit(1);
    }
    else if (child == 0) //子进程
    {
        sleep(1);
        printf("I am the child :%d\n",getpid());
        exit(0);
    }
    else //父进程
     {
        printf("I am the father:%d\n",getpid());
        exit(0);
     }
}
	
				
		
原创粉丝点击