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("P1 PID: %d\n", getpid());
- if(fork()==0) // P1
- {
- printf("P2 PID: %d, PPID: %d\n", getpid(), getppid());
- if(fork() == 0) // P1A
- {
- printf("P4 PID: %d, PPID: %d\n", getpid(), getppid());
- sleep(2);
- return 0;
- }
- if(fork() == 0) // P1B
- {
- printf("P5 PID: %d, PPID: %d\n", getpid(), getppid());
- sleep(2);
- return 0;
- }
- if(fork() == 0) // P1C
- {
- printf("P6 PID: %d, PPID: %d\n", getpid(), getppid());
- if(fork() == 0)
- {
- execlp("pstree", "pstree", "-p", pid, (char *)NULL); //pstree
- sleep(2);
- return 0;
- }
- sleep(2);
- return 0;
- }
- sleep(2);
- return 0;
- }
- if(fork()==0) // P2
- {
- printf("P2 PID: %d, PPID: %d\n", getpid(), getppid());
- if(fork() == 0) // P1A
- {
- printf("P7 PID: %d, PPID: %d\n", getpid(), getppid());
- sleep(2);
- return 0;
- }
- if(fork() == 0) // P1B
- {
- printf("P8 PID: %d, PPID: %d\n", getpid(), getppid());
- sleep(2);
- return 0;
- }
- if(fork() == 0) // P1C
- {
- printf("P9 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