Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <sys/wait.h>
- #include <time.h>
- int print_my_info(int pid){
- printf("I am process: %d and my parent is: %d and my child is: %d\n", getpid(),getppid(),pid);
- return 1;
- }
- int main()
- {
- int pid;
- int z=0;
- for(int i=1;i<=5;i++)
- {
- z++;
- if((pid=fork())>0)
- {
- print_my_info(pid);
- wait(NULL);
- exit(0);
- }
- if (z==5){
- print_my_info(pid);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement