I have this code:
Why does the process not stop after one second? And why is sigxcpu_handler never called?
Code:
volatile sig_atomic_t got_usr1;
void sigxcpu_handler(int sig)
{
got_usr1 = 1;
kill( getpid(), SIGXCPU );
}
int main(void)
{
//limit on cpu time
struct rlimit vLimCPU;
vLimCPU.rlim_cur = 1;
vLimCPU.rlim_max = 1;
setrlimit(RLIMIT_CPU, &vLimCPU);
struct sigaction sa;
got_usr1 = 0;
sa.sa_handler = sigxcpu_handler;
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
if (sigaction(SIGXCPU, &sa, NULL) == -1) {
perror("sigaction");
exit(1);
}
while (!got_usr1) {
printf("PID %d: working hard...\n", getpid());
sleep(1);
}
printf("Done in by SIGXCPU!\n");
return 0;
}