I have this code
static void sigXCPU(int pTmp){
cout<<" .... ";
}
.....
pid_t vPid=fork();
int vStat;
switch(vPid){
case -1: perror("fork");
exit(1);
case 0:
//limit on data
struct rlimit vLimD;
vLimD.rlim_cur = 100000;
vLimD.rlim_max = 1000000;
setrlimit(RLIMIT_DATA, &vLimD);
//limit on cpu time
struct rlimit vLimCPU;
vLimCPU.rlim_cur = 1;
vLimCPU.rlim_max = 1;
execl("./p1","",NULL);
if(signal(SIGXCPU,sigXCPU)==SIG_ERR);
break;
default:
while(wait(&vStat)!=vPid);
break;}
and the code for p1 is
int main(){
sleep(10);
return 0;}
Why does the child ignore SIGXCPU?The code are compiled with gcc under FreeBsd 8.0 amd64.
The code in the child after
execlis never executed, because the current process image is replaced with the application inp1.Even if you were to put the signal handler before the
execl, it would be overriden, because signal dispositions are reset to their defaults after an exec. After all, your handler function would no longer exist in the new process image.Finally, to set up a signal handler, avoid using
signaland use sigaction, instead.