Question
In C Exit Statuses Write your own function to check the exit status of a child. the function should take as input the exit status
In C Exit Statuses
Write your own function to check the exit status of a child. the function should take as input the exit status of a child and returns the followings:
1. If the child terminated normally or abnormally.
2. If the child terminated normally, it should return its exit status.
3. If the child terminated abnormally, it should return the signal number that caused the abnormal termination.
4. The programs output should look as follows:
The exit status for child 2345 using my status check function is : Normal termination , exit status is : 205
The exit status for child 2345 using C status check macros is : Normal termination , exit status is : 205
The exit status for child 5734 using my status check function is : Abnormal termination , signal is : 8
The exit status for child 5734 using C status check macros is : Abnormal termination , signal is : 8
Code:
#include#include #include #include #include #include #define N 6 void My_Exit_Status_Check(int status) { // Add your code here } void C_Macros_Exit_Status_Check(int status) { // Add your code here } int main() { unsigned int status, i; pid_t pid; /* Parent creates N children */ for(i = 0; i < N; i++) if((pid = fork()) == 0) /* child */ { if(i == 3) exit(i/0); exit(100 + i); } /* Parent reaps N children in no particular order */ while ((pid = waitpid(-1, &status, 0)) > 0) { My_Exit_Status_Check(status); // call your code here. C_Macros_Exit_Status_Check(status); // and here. } /* The only normal termination is if there are no more children */ if (errno != ECHILD) perror("waitpid error"); exit(0); }
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