Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use SIGRTMAX and SIGRTMIN?

I do know how signals are real time signals defined in POSIX. However I was curious to know how to use these or rather how are these signals generated? like a SIGSEGV is generated on invalid memory reference, a SIGINT is generated on a keyboard interrupt like ctrl+c.

How are signals like SIGRTMAX and SIGRTMIN generated and used ?

like image 294
Anurag Avatar asked Jan 07 '23 19:01

Anurag


1 Answers

Actually I did figure it out how to generate signals for SIGRTMAX and SIGRTMIN.

If someone comes across this in the future then-

First you use the struct sigaction , set the member as per your requirements. Set sa_handler to the function you want that handles the signal generation.

To put this into action you use the function sigaction() pass the arguments as specified in linux manual.

So now you use the struct sigevent set the members there in to specify the signal number to be handled and how you send the notification for it.

With this you have done the setup, now you need to create a phenomena or event which would generate the signal maybe like expiration of time.

This you do by getting a timer handler by timer_create() this associates your sigevent with the handler.

Then you setup the expiration interval using struct itimerspec and then using timer_settime() you associate the expiration with the handler.

So now the expiration is associated with the handler, the time handler is associated with sigevent and sigevent redirects that signal to the handler set by sigaction

like image 87
Anurag Avatar answered Jan 16 '23 23:01

Anurag