everyone. I've got a problem that is making me very confused. I'm just trying to print out the status received from a terminated process but it isn't working the way I thought it would. Here is the code.
int main(int argc, char *argv[])
{
printf("this process (%d)\n",(int)(getpid()));
int *status;
pid_t pid;
Signal(SIGINT, handler1);
if ((pid = fork())==0){
while(1)
;
}
kill(pid,SIGINT);
while(pid>0){
pid = waitpid(pid,status,0);
printf("status: %d\n", WEXITSTATUS(status));
printf("waitpid return: %d\n",(int)pid);
}
return 0;
}
void handler1(int sig){
printf("process (%d) has received a sigint\n",(int)(getpid()));
exit('d');
}
it has output
this process (8811)
process (8812) has received a sigint
status: 0
waitpid return: 8812
status: 0
waitpid return: -1
when I use WIFEXITED(status) it returns true. So shouldn't WEXITSTATUS return what I passed through exit and not 0?
I did not include the Signal function here.