如何解决如何在c
所以我目前正在学习C语言中的fork()系统调用,但是我似乎无法完全了解正在发生的事情。
这是代码
int id=fork();
int child_id,status;
//if id == 0 we are in the child process
if(id == 0 )
{
int pid = getpid()
printf("this is the child process %d\n",pid);
int id1=fork()
if(id1==0)
{
//this will return the pid of the grandparent
int pid2 = getppid();
printf("this is child no 2 process %d\n",pid2);
}
else
{
child_id = wait(&status);
printf("this is parent(%d) of child no 2\n",pid)
}
}
else
{
child_id = wait(&status);
printf("this is the parent process and we will execute after child %d\n",child_id);
}
这就是我的可视化方式。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。