Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- int main()
- {
- char pid[50];
- sprintf(pid, "%d", getpid());
- printf("Root PID: %d\n", getpid());
- if(fork() == 0)
- {
- printf("1 PID: %d\n", getpid());
- if(fork() == 0)
- {
- printf("11 PID: %d\n", getpid());
- sleep(2);
- return 0;
- }
- if(fork() == 0)
- {
- printf("12 PID: %d\n", getpid());
- sleep(2);
- return 0;
- }
- sleep(2);
- return 0;
- }
- if(fork() == 0)
- {
- printf("2 PID: %d\n", getpid());
- if(fork() == 0)
- {
- printf("21 PID: %d\n", getpid());
- sleep(2);
- return 0;
- }
- if(fork() == 0)
- {
- printf("22 PID: %d\n", getpid());
- sleep(2);
- return 0;
- }
- sleep(1);
- execlp("pstree", "pstree", "-c", pid, (char *)NULL);
- }
- if(fork() == 0)
- {
- printf("3 PID: %d\n", getpid());
- if(fork() == 0)
- {
- printf("31 PID: %d\n", getpid());
- sleep(2);
- return 0;
- }
- if(fork() == 0)
- {
- printf("32 PID: %d\n", getpid());
- if(fork() == 0)
- {
- printf("321 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