1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

c++ limit process child ignore SIGXCPU

Discussion in 'Userland Programming and Scripting' started by xnl96, May 1, 2012.

  1. xnl96

    xnl96 New Member

    Messages:
    48
    Thanks Received:
    2
    I have this code
    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
    Code:
    int main(){
      sleep(10);
    return 0;}
    Why does the child ignore SIGXCPU?
     
  2. anon12b

    anon12b New Member

    Messages:
    17
    Thanks Received:
    5
    If I understand your question, then the answer is because execl(3) never returns (unless in error, see the man page). The code between the execl(3) and the next case statement is not run, assuming the called program can be executed. Therefore, your call to signal(3) never happens, and, thus, your callback is never registered.