I am using the Linux ptrace API in a profiler I am writing.
My pseudo C code looks like this:
setjmp();
measure();
alarm(N);
while(1) {
waitpid(child, &status, WNOHANG);
if(child_process_exiting) {
measure();
break;
}
}
The alarm signal handler is as follows:
void sig_handler(int sig) {
signal(SIGALRM, sig_handler);
longjmp(env, 0);
}
I want to repeatedly return to the setjmp call until the child process exits and breaks the loop. The goal is to run the measure function every N seconds until the child process exits.