Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/types.h>
- #include <unistd.h>
- #include <stdio.h>
- int main(void)
- {
- char pid[10];
- sprintf(pid, "%d", getpid());
- int myPID = getpid();
- printf("Parent PID: %d\n", getpid());
- if(fork()==0) // P1
- {
- printf("1 PID: %d, PPID: %d\n", getpid(), getppid());
- if(fork() == 0) // P1A
- {
- printf("1A PID: %d, PPID: %d\n", getpid(), getppid());
- sleep(2);
- return 0;
- }
- sleep(2);
- return 0;
- }
- if(fork()==0) // P2
- {
- printf("2 PID: %d, PPID: %d\n", getpid(), getppid());
- if(fork() == 0) // P2A
- {
- printf("2A PID: %d, PPID: %d\n", getpid(), getppid());
- if(fork() == 0) // P2AA
- {
- printf("2AA PID: %d, PPID: %d\n", getpid(), getppid());
- sleep(2);
- return 0;
- }
- if(fork() == 0) // P2AB
- {
- printf("2AB PID: %d, PPID: %d\n", getpid(), getppid());
- }
- sleep(2);
- return 0;
- }
- if(fork() == 0) // P2B
- {
- printf("2B PID: %d, PPID: %d\n", getpid(), getppid());
- // execlp("pstree","pstree", "-p",pid,(char *)NULL);//pstre
- // tu powinno byc ale nie dziala
- if(fork() == 0) // P2BA
- {
- printf("2BA PID: %d, PPID: %d\n", getpid(), getppid());
- sleep(2);
- return 0;
- }
- if(fork() == 0) // P2BB
- {
- execlp("pstree","pstree", "-p",pid,(char *)NULL);//pstre
- printf("2BB PID: %d, PPID: %d\n", getpid(), getppid());
- sleep(2);
- return 0;
- }
- if(fork() == 0) // P2BC
- {
- printf("2BC PID: %d, PPID: %d\n", getpid(), getppid());
- sleep(2);
- return 0;
- }
- sleep(2);
- return 0;
- }
- }
- sleep(2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement