赞
踩
今天在测试共享内存时编写了一个进程测试的代码,在调用fork函数创建子进程时,在父进程中返回子进程pid,在子进程中返回0;具体代码如下:
#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());
}
}

在运行这段程序时出现了下面的结果:
hello@hello-machine:~/study-linux/unix_c/12-mem_share
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。