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>
- 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=fork();
- if(pid>0){
- printf("0:");
- print_my_info(pid);
- }
- else{
- pid=fork();
- if(pid>0){
- printf("1:");
- print_my_info(pid);
- }
- else{
- pid=fork();
- if (pid>0){
- printf("2:");
- print_my_info(pid);
- }
- else{
- pid=fork();
- if(pid>0){
- printf("3:");
- print_my_info(pid);
- }
- else{
- pid=fork();
- if(pid>0){
- printf("4:");
- print_my_info(pid);
- }
- else{
- printf("5:");
- print_my_info(pid);
- }
- }
- }
- }
- }
- wait(NULL);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement