进程扇:
#include <stdio.h>
#include <fcntl.h>
int main(void)
{
pid_t pid;
int i = 0;
for(i; i<10;i++)
{
pid = fork();
if(pid == 0)
{
printf("this is a child %d\n", getpid());
exit(0);
}
}
//阻塞,等待收尸
for(i=0; i<10; i++)
wait(NULL);
printf("this is a parent %d\n". getpid());
return 0;
}
进程链:
#include <stdio.h>
#include <fcntl.h>
int main(void)
{
pid_t pid;
int i = 0;
for(i; i<10;i++)
{
pid = fork();
if(pid > 0)
{
break;
}
}
//加上此句,递减输出pid(父进程等待给子进程收尸),否则递增输出pid
wait(NULL);
printf("this is a parent %d\n". getpid());
return 0;
}