You can use long inside the signal handler, you can use anything, actually. The only thing you should take care of is proper synchronization to avoid race conditions.
sig_atomic_t should be used for variables shared between the signal handler and the rest of the code. Any "private" variable for a signal handler can be of any type, any size.
Code example:
#include <signal.h> static volatile long badShared; // NOT OK: shared not sig_atomic_t static volatile sig_atomic_t goodShared; // OK: shared sig_atomic_t void handler(int signum) { int localInt = 17; long localLong = 23; // OK: not shared if (badShared == 0) // NOT OK: shared not sig_atomic_t ++badShared; if (goodShared == 0) // OK: shared sig_atomic_t ++goodShared; } int main() { signal(SOMESIGNAL, handler); badShared++; // NOT OK: shared not sig_atomic_t goodShared++; // OK: shared sig_atomic_t return 0; }
If you want to use a shared variable other than sig_atomic_t , use atomics ( atomic_long_read , atomic_long_set ).
source share