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()); //P
- 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) //P1AA
- {
- printf("1AA PID: %d, PPID: %d\n", getpid(), getppid());
- 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());
- if (fork() == 0) //P2AA
- {
- printf("2AA PID: %d, PPID: %d\n", getpid(), getppid());
- sleep(2);
- return 0;
- }
- execlp("pstree", "pstree", "-c", pid, (char*)NULL); //pstree
- sleep(2);
- return 0;
- }
- if (fork() == 0) //P2B
- {
- printf("2B PID: %d, PPID: %d\n", getpid(), getppid());
- if (fork() == 0) //P2BA
- {
- printf("2BA PID: %d, PPID: %d\n", getpid(), getppid());
- sleep(2);
- return 0;
- }
- if (fork() == 0) //P2BB
- {
- printf("2BB PID: %d, PPID: %d\n", getpid(), getppid());
- sleep(2);
- return 0;
- }
- sleep(2);
- return 0;
- }
- if (fork() == 0) //P2C
- {
- printf("2C PID: %d, PPID: %d\n", getpid(), getppid());
- sleep(2);
- return 0;
- }
- }
- sleep(2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement