#include <stdio.h>
#include<unistd.h>
int main()
{
pid_t pid;
int count=0;
pid = vfork();
if(pid == 0)
{
count++;
printf("count = %d\n",count);
_exit(0);
}
else
{
count++;
printf("count = %d\n",count);
return 0;
}
}
#include<unistd.h>
int main()
{
pid_t pid;
int count=0;
pid = vfork();
if(pid == 0)
{
count++;
printf("count = %d\n",count);
_exit(0);
}
else
{
count++;
printf("count = %d\n",count);
return 0;
}
}
本文提供了一个使用vfork函数创建子进程的C语言示例代码。通过该示例,读者可以了解如何在子进程中修改变量并在父子进程中分别打印其值。此外,还展示了如何在子进程中调用_exit来终止进程。
1万+

被折叠的 条评论
为什么被折叠?



