I am forking a child process to run a command using execve
. I am installing and defining 3 signal handlers: SIGCHLD,SIGINT and SIGSTP as follows:
void sigchld(int sig)
{
while((pid=waitpid(-1,&stat,WNOTRACE|WNOHANG))>0)
{
if(WIFEXITED(stat))
//normal exit: Delete child from job list
if(WIFSIGNALED(stat))
//interrupted by signal: delete job from job list
if(WIFSTOPPED(stat))
//Stopped: put child in background
}
}
//SIGINT Handler:
kill(-pid,sig)
//SIGSTOPPED Handler:
kill(-pid,sig)
Now, when I run a process and put it in background(ctrl z) in a loop(100 times), in most cases I get error: waitpid error: Interrupted system call
Why am I getting this?