you will write a working program test1A.c that creates two child processes A1 an
ID: 3802939 • Letter: Y
Question
you will write a working program test1A.c that creates two child processes A1 and A2. Then, write another program test1B.c that creates a child process B1 that, in turn, loads and executes program test1A.c (that is, child process B1 is responsible for executing program test1A.c). To ensure that your programs work, be sure to have each process perform some I/O at key points.
so i created test1A.c like below. so my question is that Is it possible for the parent process in test1A.c to terminate one of its child processes, say A1 or A2? Now, is it possible for the parent process in test1B.c to terminate one of its grandchild processes, say A1 or A2? If so, how? Hint: Using exit to pass data between the child and parent will not work in this case.
can you add some codes for me? thanks
int main()
{
int fd;
pid_t pid;
pid = fork();
if (pid < 0)
{
fprintf(stderr, "Error");
exit(EXIT_FAILURE);
}
//child 1
else if (pid == 0)
{
printf("I am child 1. ");
}
else
{
pid = fork();
// child 2
if (pid == 0)
{
printf("I am child 2. ");
}
else
{
wait (NULL);
exit(EXIT_SUCCESS);
}
}
}
Explanation / Answer
Yes its possible for a parent process to kill one of its child process.
please check the following for reference:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.