当前位置:   article > 正文

进程学习——父进程子进程ID_父进程pid

父进程pid
今天在测试共享内存时编写了一个进程测试的代码,在调用fork函数创建子进程时,在父进程中返回子进程pid,在子进程中返回0;具体代码如下:
  • 1
#include <unistd.h>
#include <stdio.h>

int main()
{
    pid_t pid;
    pid = fork();

    //父进程
    if(pid != 0)
    {
        printf("this is father, child pid = %d\n", pid);
    }

    //子进程
    if(pid == 0)
    {
        printf("this is child, father pid = %d\n", getppid());
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

在运行这段程序时出现了下面的结果:
hello@hello-machine:~/study-linux/unix_c/12-mem_share

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/人工智能uu/article/detail/882953
推荐阅读
相关标签
  

闽ICP备14008679号