|
#include <cstdio>
#include <unistd.h>
int main()
{
pid_t pid;
pid = fork();
switch (pid)
{
case -1:
{
perror("fork failed");
}
break ;
case 0:
{
pid = fork();
if (pid == -1)
{
perror("fork child failed");
}
else if (pid == 0)
{
printf("wo shi child child\n");
sleep(50);
return 0;
}
else
{
printf("wo shi chilid\n");
sleep(100);
return 0;
}
}
break ;
default:
{
printf("wo shi parent\n");
sleep(200);
}
break ;
}
return 0;
} |
|