#include
int main()
{
int pid;
/*这里创建了一个子进程1*/
pid=fork();
if(pid==0)
printf("I am son,my pid is %d.\n",getpid());
else if(pid>0)
{
/*从子进程1返回到父进程时,再创建子进程2。*/
printf("I'm father ,my pid is %d.\n",getpid());
pid=fork();
if(pid==0)
printf("I'm daughter process,my pid is %d.\n",getpid());
else if(pid>0)
printf("I'm father process,my pid is %d.\n",getpid());
else
printf("fork() error.\n");
}
else printf("fork() error.\n");
}