日期:2014-05-16 浏览次数:20824 次
#include<errno.h>
#include<error.h>
#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<stdlib.h>
#include<string.h>
char command[256];
int main()
{
pid_t pc,pr,status=0;
pc = fork();
if(pc < 0)
{
printf("error occurred when creating child process!\n");
}
else if(pc == 0)
{
printf("child process with pid of %d\n",getpid());
exit(5);
}
else
{
sleep(1);
pr = wait(&status);
printf("parent catched a child process with pid of %d %d",pr,status);
}
exit(0);
return 0;
}