Assume that a folder contains the four files main.c, hello.c, main, and hello.
Here main.c and hello.c contains following source code. main and hello are
executable files of main.c and hello.c respectively. In this case, write the output
generated after the execution of "main.c"?
Ans.)
CPCRP
/* main.c*/
#include<stdio.h>
#include<unistd.h>
int main () {
char *args[] = {"hello", 0, 0, NULL};
pid_t pid=vfork();
if (pid == 0)
printf ("C");
else
{
printf ("P");
execv("hello", args);
printf ("R");
}
printf ("F");
return 0;
}
/* hello.c */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main (int argc, char *argv []) {
if (vfork() || vfork())
printf ("P");
else
printf ("C");
exit(0);
}