操作系统 --进程控制

    科技2024-07-13  68

    操作系统的

    #include <sys/types.h> #include <unistd.h> #include <stdio.h> int main() { int p1,p2,i; while((p1=fork())==-1); if(p1==0) { for(int i=1; i<=5000000; i++) if(i%1000000==0) printf("son %d\n",getpid()); } else { while((p2=fork())==-1); if(p2==0) { for(int i=1; i<=5000000; i++) if(i%1000000==0) printf("daughter%d\n",getpid()); } else { for(int i=1; i<=5000000; i++) if(i%2000000==0) printf("father%d\n",getpid()); } } return 0; }
    Processed: 0.017, SQL: 8