进程链进程扇
进程链
#include <stdio.h> #include <sys/types.h> #include <unistd.h> int main(void) { pid_t pid; int i; //printf("pid = %d\n",getpid()); for(i = 0; i< 5;i++ ){ pid = fork(); if(0 == pid){ printf("child pid = %d\n",getpid()); }else if(pid > 0){ break; }else{ printf("error\n"); } } printf("pid = %d,ppid = %d\n",getpid(),getppid()); sleep(3); return 0; }
进程扇
int main(void) { pid_t pid; int i; //printf("pid = %d\n",getpid()); for(i = 0; i< 5;i++ ){ pid = fork(); if(0 == pid){ break;//子进程退出循环 }else if(pid > 0){ printf("father pid = %d\n",getpid()); }else{ printf("error\n"); } } printf("pid = %d,ppid = %d\n",getpid(),getppid()); sleep(3); return 0; }