Question
#include #include #include int main (int args, char *argv[]) { pid_t fork_return; pid_t pid; pid=getpid(); fork_return = fork(); // When fork() returns -1, an error
#include
#include
#include
int main (int args, char *argv[])
{
pid_t fork_return;
pid_t pid;
pid=getpid();
fork_return = fork();
// When fork() returns -1, an error happened.
if (fork_return==0)
// When fork() returns 0, we are in the child process.
{
printf("n The values are Child ID = %d, Parent ID=%d ", getpid(), getppid());
execl("/bin/cat", "cat", "-b", "-v", "-t", argv[1], 0);
}
else
// When fork() returns a positive number, we are in the parent process
// and the return value is the PID of the newly created child process.
{
wait(NULL);
printf(" Child Completes " );
printf(" In the Parent Process ");
printf("Child Id = %d, Parent ID = %d ", getpid(), getppid());
}
return 0;
}
Q1 Once this program is typed, and executed, answer the following questions
a. If you try to print a message after the exec* call, does it print it? Why? Why not?
b. Who is the parent of your executable program?
c. How would you change the code so that the child and parent run concurrently?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started