I don't understand why after the first execution of kill function the sleep function doesn't pause the parent process. After the SIGINT has been delivered, many processes are generated. Furthermore, it seems that a variable number of processes is generated. Is a handler for SIGINT required for cleaning the first SIGINT from the pending signals?
void handler(int s) {
int status;
wait(&status);
printf("\n in the handler");
if (WIFSIGNALED(status)) {
int sig=WTERMSIG(status);
printf("\n child stopped by signal %d\n",sig);
}
if (WIFEXITED(status)) {
int ex=WEXITSTATUS(status);
printf("\n child stopped with exist status %d\n",ex);
}
}
int main() {
int pid,len, count, ret;
char s[1024];
signal(SIGCHLD,handler);
while(1) {
pid=fork();
if (pid==0) {
printf("\n Write something ");
scanf("%s",s);
len=strlen(s);
printf("\n Characters: %d",len);
return 1;
}
else {
sleep(20);
kill(pid,SIGINT);
}
}
}