Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <sys/types.h>
- int main(){
- pid_t pot[10];
- //Proces macierzysty P1
- switch (pot[1]=fork()){
- case 0:
- //Proces potomny P2
- switch(pot[2]=fork()){
- case 0:
- //Proces potomny P4
- switch(pot[4]=fork()){
- case 0:
- printf("P4:%d:%d\n", getpid(),getppid());
- exit(0);
- case -1:
- printf("Blad\n");
- exit(1);
- default:
- wait(NULL);
- }
- //Proces potomny P5
- switch(pot[5]=fork()) {
- case 0:
- //Proces potomny P8
- switch (pot[8] = fork()) {
- case 0:
- printf("P8:%d:%d\n", getpid(), getppid());
- exit(0);
- case -1:
- printf("Blad\n");
- exit(1);
- default:
- wait(NULL);
- }
- //Proces potomny P9
- switch (pot[9] = fork()) {
- case 0:
- printf("P9:%d:%d\n", getpid(), getppid());
- exit(0);
- case -1:
- printf("Blad\n");
- exit(1);
- default:
- wait(NULL);
- }
- //Dalsza czesc procesu P5
- case -1:
- printf("Blad\n");
- exit(1);
- default:
- printf("P1:%d:%d:%d\n", getpid(), getppid(), pot[8], pot[9]);
- wait(NULL);
- }
- //Dalsza czesc procesu P2
- case -1:
- printf("Blad\n");
- exit(1);
- default:
- printf("P1:%d:%d:%d\n", getpid(), getppid(), pot[4], pot[5]);
- wait(NULL);
- }
- //Proces potomny P3
- switch(pot[3]=fork()){
- case 0:
- //Proces potomny P6
- switch(pot[6]=fork()){
- case 0:
- printf("P6:%d:%d\n", getpid(),getppid());
- exit(0);
- case -1:
- printf("Blad\n");
- exit(1);
- default:
- wait(NULL);
- }
- //Proces potomny P7
- switch(pot[7]=fork()){
- case 0:
- //Proces potomny P10
- switch(pot[10]=fork()){
- case 0:
- printf("P10:%d:%d\n", getpid(),getppid());
- exit(0);
- case -1:
- printf("Blad\n");
- exit(1);
- default:
- wait(NULL);
- }
- //Dalsza czesc procesu P7
- case -1:
- printf("Blad\n");
- exit(1);
- default:
- printf("P1:%d:%d:%d\n", getpid(), getppid(), pot[10]);
- wait(NULL);
- }
- //Dalsza czesc procesu P3
- case -1:
- printf("Blad\n");
- exit(1);
- default:
- printf("P1:%d:%d:%d:%d\n", getpid(), getppid(), pot[6], pot[7]);
- wait(NULL);
- }
- //Dalsza czesc procesu P1
- case -1:
- printf("Blad\n");
- exit(1);
- default:
- printf("P1:%d:%d:%d:%d\n", getpid(), getppid(), pot[2], pot[3]);
- wait(NULL);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement