Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<sys/types.h>
- #include<stdio.h>
- #include<stdlib.h>
- #include<unistd.h>
- // ______P1____
- // / | \
- // ___P2_ P3 P4
- // / | \ / \ |
- // P5 P6 P7 P8 P9 P10
- // | |
- // P11 (P12) <-- pstree
- int pid;
- int main(void)
- {
- printf("Proces 1 PID:%d\n", getpid());
- if(pid=fork())//2
- {
- printf("Proces 2 PID:%d\n", pid);
- }
- else
- {
- if(pid=fork())//5
- {
- printf("Proces 5 PID:%d\n", pid);
- }
- else
- {
- sleep(1);
- exit(0);
- }
- if(pid=fork())//6
- {
- printf("Proces 6 PID:%d\n", pid);
- }
- else
- {
- if(pid=fork())//11
- {
- printf("Proces 11 PID:%d\n", pid);
- }
- else
- {
- sleep(1);
- exit(0);
- }
- sleep(1);
- exit(0);
- }
- if(pid=fork())//7
- {
- printf("Proces 7 PID:%d\n", pid);
- }
- else
- {
- sleep(1);
- exit(0);
- }
- sleep(1);
- exit(0);
- }
- if(pid=fork())//3
- {
- printf("Proces 3 PID:%d\n", pid);
- }
- else
- {
- if(pid=fork())//8
- {
- printf("Proces 8 PID:%d\n", pid);
- if(pid=fork())//9
- {
- printf("Proces 9 PID:%d\n",pid);
- }
- else
- {
- sleep(1);
- exit(0);
- }
- }
- else
- {
- sleep(1);
- exit(0);
- }
- sleep(1);
- exit(0);
- }
- if(pid=fork())//4
- {
- printf("Proces 4 PID:%d\n", pid);
- }
- else
- {
- if(pid=fork())//10
- {
- printf("Proces 10 PID:%d\n", pid);
- }
- else
- {
- if(pid=fork())
- {
- printf("Proces 12 PID:%d\n", pid);
- }
- else
- {
- //system("pstree -c");
- execlp("pstree","pstree","-c",(char*)NULL);
- sleep(1);
- exit(0);
- }
- sleep(1);
- exit(0);
- }
- sleep(1);
- exit(0);
- }
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement