I rewrite the code with sigaction, thanks for warning me about it.
Actually the problem is using sleep() to waste time (APPLICATION USAGE section - http://www.opengroup.org/onlinepubs/009695399/functions/sigaction.html)! If I use some other method to keep the process running, the signal is caught every time. I also need to set timer each time a signal is caught. This code behaves as a want
struct itimerval it;
long unsigned int fibonacci (unsigned int n)
static void sig_handler(int sig)
struct sigaction sa;
sa.sa_handler = sig_handler;
sa.sa_flags = SA_RESTART;