LinuxDriver/Linux系统编程篇/04进程基础/getpid.c

24 lines
359 B
C

#include <stdio.h>
#include <unistd.h>
int main(void)
{
pid_t pid;
pid = fork();
if (pid < 0)
{
printf("fork is error\n");
return -1;
}
// 父进程
if (pid > 0) {
printf("This is parent, parent pid is %d\n",getppid());
}
// 子进程
if (pid == 0){
printf("This is child, child pid is %d\n",getpid());
}
return 0;
}