I have c code as such
int childid;
int parentid;
void siginthandler(int param)
{
// if this is the parent process
if(getpid() == parentid){
//handler code which sends SIGINT signal to child process
kill(childid, SIGINT);
}
else // if this is the child process
exit(0);
}
int main()
{
parentid = getpid(); // store parent id in variable parentid, for the parent as well as child process
int pid = fork();
int breakpid;
if(pid != 0){
childid = pid;
breakpid = wait();
printf("pid = %d\n", breakpid);
}
else
sleep(1000);
}
Now, when I run this code, the parent process waits, while the child process sleeps. If I now interrupt (by pressing ctrl+c) the parent program, UNIX (POSIX standard) documentation tells me that the wait function should return -1, with errno set to EINTR. My code implementation however, kills the child process since the parent process sends the SIGINT signal to the child process. But, surprisingly,(in the parent process) wait does not return pid = -1 with errno set to EINTR. Instead, it returns the id of the child process, which got killed.
Is there an explanation for this?