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){//P22 prawo od macierzystego
- printf("7.prawo PID: %d\n", getpid());
- if(fork()==0){//P23 prawo
- printf("8.prawo PID: %d\n", getpid());
- if(fork()==0){//P24 lewo
- printf("9.prawo PID: %d\n", getpid());
- sleep (2);
- return 0;
- }
- if(fork()==0){//P25 prawo
- printf("10.prawo PID: %d\n", getpid());
- sleep(2);
- return 0;
- }
- sleep(2);
- return 0;
- }
- sleep(2);
- return 0;
- }
- if (fork()==0){//P1 lewy
- printf("1.Lewo PID: %d\n", getpid());
- if (fork()==0){//P2 prawy X
- printf("5.prawo PID: %d\n", getpid());
- if (fork()==0){//P3 prawy
- printf("6.prawo PID: %d\n", getpid());
- sleep (2);
- return 0;
- }
- execlp("pstree", "pstree", "-c", pid, (char *)NULL); //pstrees
- sleep(2);
- return 0;
- }
- if(fork()==0){//P2 lewy
- printf("2.Lewo PID: %d\n", getpid());
- if(fork()==0){//P3 lewy
- printf("3.Lewo PID: %d\n", getpid());
- sleep(2);
- return 0;
- }
- if(fork()==0){//P3 prawy
- printf("4.prawo PID: %d\n", getpid());
- sleep(2);
- return 0;
- }
- sleep(2);
- return 0;
- }
- sleep (2);
- return 0;
- }
- sleep(2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement