what is the relation between SIGTSTP and SIGCHLD
- by Rawhi
I have tow handlers for each one of them (SIGTSTP, SIGCHLD), the thing is that when I pause a process using SIGTSTP the handler function of SIGCHLD run too. what should I do to prevent this .
void ExeExternal(char *args[MAX_ARG], char* cmdString, LIST_ELEMENT** pList, int *Susp_Bg_Pid, int *susp) {
int pID, status, w;
switch (pID = fork()) {
case -1:
perror("smash error: >");
break;
case 0:
// Child Process
setpgrp();
execv(args[0], args);
execvp(args[0], args);
perror("error");
exit(EXIT_FAILURE);
break;
default:
if (cmdString[strlen(cmdString) - 1] != '&') {
*Susp_Bg_Pid = pID;
*susp = 1;
while(*susp);
} else {
InsertElem(pList, args[0], getpid(), pID, 0);
}
break;
}
}
signal handlers :
void signalHandler(int signal) {
int pid, cstatus;
if (signal == SIGCHLD) {
susp = 0;
pid = waitpid(-1, &cstatus, WNOHANG);
printf("[[child %d terminated]]\n", pid);
DelPID(&JobsList, pid);
}
}
void ctrlZsignal(int signal){
kill(Susp_Bg_Pid, SIGTSTP);
susp = 0;
printf("\nchild %d suspended\n", Susp_Bg_Pid);
}
Susp_Bg_Pid used to save the paused process id.
susp indicates the state of the "smash" the parent process if it is suspended or not .