Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a standard library function in signal handler

Tags:

c

unix

gcc

signals

Why is calling a standard library function inside a signal handler discouraged?

like image 764
Abhijeet Rastogi Avatar asked Mar 17 '10 10:03

Abhijeet Rastogi


1 Answers

This is explained in the GNU LibC documentation.

If you call a function in the handler, make sure it is reentrant with respect to signals, or else make sure that the signal cannot interrupt a call to a related function.

And just in case, here's the Wikipedia page on reentrant functions.

A computer program or routine is described as reentrant if it can be safely called again before its previous invocation has been completed (i.e it can be safely executed concurrently).

like image 102
Macmade Avatar answered Oct 01 '22 09:10

Macmade