linux进程
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
pid_t pid;
pid = fork();
if(pid < 0)
{
perror("fork failed");
exit(1);
}
if(0 == pid)
{
printf("This is the child, child pid = %d\n", getpid());
}
else//pid>0
{
printf("This is the parent, parent pid = %d\n", getpid());
printf("This is the parent, child pid = %d\n", pid);
}
return 0;
}
源码1