evfork.c
来自「深圳英培特EduKit-III实验箱实验程序。一共有10多个」· C语言 代码 · 共 32 行
C
32 行
/*********************************************************************
* File: evfork.c
* Author: Embest J.Zhao 2005.2.17
* Desc: processes
* History:
*********************************************************************/
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
main()
{
int pid;
//creat the child process.
pid=vfork();
//execute process according to the pid returned.
if (pid < 0)
//creat failed.
printf("error in fork!\n");
else if (pid == 0)
//return 0 ,exec the child.
printf("i am the child process, my process id is %d\n",getpid());
else
{
//return the child pid,exec the parent.
printf("i am the parent process, my process id is %d\n",getpid());
exit(0);
}
printf("end pid is %d\n",getpid());
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?