Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/types.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- int main ()
- {
- pid_t pid ;
- printf("Parent process is running and about to fork to a child process\n") ;
- pid = fork() ;
- if (pid<0)
- {
- fprintf(stderr, "Fork failed") ;
- return 1 ;
- }
- else if (pid==0)
- {
- printf("I am the child process\n") ;
- exit(0) ;
- }
- else
- {
- wait(NULL) ;
- printf("Parent acknowledges child termination Parent will terminate now\n") ;
- }
- return 0 ;
- }
- Output with "gcc Asg3iia.c -o Asg3iia.out && ./Asg3iia.out" :
- Parent process is running and about to fork to a child process
- I am the child process
- Parent acknowledges child termination Parent will terminate now
- Output with "gcc Asg3iia.c -o Asg3iia.out && ./Asg3iia.out | less" :
- Parent process is running and about to fork to a child process
- I am the child process
- Parent process is running and about to fork to a child process
- Parent acknowledges child termination Parent will terminate now
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement