Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/types.h>
- #include <unistd.h>
- int main(void){
- char pid[10];
- sprintf(pid, "%d", getpid());
- printf("Macierzysty PID: %d\n", getpid());
- if (fork()==0){//P1 lewy
- printf("P1 lewy PID: %d\n", getpid());
- if (fork()==0){//P11 lewy
- printf("P11 lewy PID: %d\n", getpid());
- if (fork()==0){ //P111 lewy
- printf("P111 lewy PID: %d", getpid());
- sleep (120);
- return 0;}
- if (fork()==0){ //P112 prawy
- printf("P112 prawy PID: %d", getpid());
- sleep (120);
- return 0;}
- sleep (120);
- return 0;}
- if(fork()==0){//P12 prawy X
- printf("P12 prawy PID: %d\n", getpid());
- //exec
- if(fork()==0) {//P22 prawy
- printf("P22 lewy PID: %d\n", getpid());
- sleep (120);
- return 0;}
- execlp("pstree", "pstree", "-c", getpid(), (char *)NULL);
- sleep(120);
- return 0;}
- }
- if (fork()==0){//P22 prawy
- printf("P22 prawy PID: %d\n", getpid());
- if(fork()==0){//P22 prawy
- printf("P22 prawy PID: %d\n", getpid());
- if(fork()==0){//P221 lewy
- printf("P221 lewy PID: %d\n", getpid());
- sleep (120);
- return 0;}
- if (fork()==0){//P222 prawy
- printf("P222 prawy PID: %d\n", getpid());
- sleep (120);
- return 0;}
- sleep (120);
- return 0;}
- sleep(120);
- return 0;}
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement