创建子进程,并打印父进程和子进程的ID
#include <unistd.h>
#include <stdio.h>
int main()
{
pid_t pid;
pid = fork();
if(pid < 0)
{
printf("error in fork\n");
}
else if(0 == pid){
printf("This is chile process, ID is %d\n", getpid());
}
else{
printf("This is parent process, ID is %d\n", getpid());
}
return 0;
}