Guru Prasad
Guru Prasad

Reputation: 4223

Create new signal or multiplex SIGALRM?

I am trying to write a benchmark that receives a signal from the kernel telling it to adjust its parameters. I'm trying to study whether a proactive or reactive approach works best.

In the proactive approach, I use setitimer to set an alarm periodically and force the benchmark to look at its performance thus far and re-tune itself.

In the reactive approach, the kernel periodically monitors the process and signals it if it is performing poorly.

Since I've been using the setitimer functionality, and since setitimer causes SIGALRM, I have asked the kernel to throw a SIGALRM in the reactive approach. This has been working fine. However, now I need to use SIGALRM to run the benchmark for a specific duration of time.

Is there a way to multiplex SIGALRM to serve both purposes - to do a timed run and terminate and to re-tune. Is there a function/syscall similar to setitimer that allows the user to set an alarm but with a custom signal?

Upvotes: 1

Views: 155

Answers (1)

Duck
Duck

Reputation: 27552

Yes. You want to look at the timer_create / timer_settime etc., family of calls.

The 2nd parameter of timer_create is a struct sigevent. The field within that, sigev_signo can be set to send a specific signal number on timer expiration.

Upvotes: 1

Related Questions