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