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());
- if(fork() == 0)
- {
- printf("1AA PID: %d, PPID: %d\n", getpid(), getppid());
- 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("2 PID: %d, PPID: %d\n", getpid(), getppid());
- if(fork() == 0) // P2A
- {
- printf("2A PID: %d, PPID: %d\n", getpid(), getppid());
- sleep(2);
- return 0;
- }
- if(fork() == 0) // P2B
- {
- printf("2B PID: %d, PPID: %d\n", getpid(), getppid());
- sleep(2);
- return 0;
- }
- sleep(2);
- return 0;
- }
- if(fork()==0) // P3
- {
- printf("3 PID: %d, PPID: %d\n", getpid(), getppid());
- if(fork() == 0) // P3A
- {
- printf("3A PID: %d, PPID: %d\n", getpid(), getppid());
- sleep(2);
- return 0;
- }
- if(fork() == 0) // P3B
- {
- printf("3B PID: %d, PPID: %d\n", getpid(), getppid());
- if(fork()==0) // P3BB
- {
- printf("3BB PID: %d, PPID: %d\n", getpid(), getppid());
- sleep(2);
- return 0;
- }
- sleep(2);
- return 0;
- }
- if(fork() == 0) // P3C
- {
- printf("3C 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