Lately have been testing out using signals such as SIGINT and SIGHUP and their role on ongoing processes on Linux. Running the following code returned some interesting results.
#include <signal.h> #include <stdio.h> void routine(int p){ puts("Not finishing"); sleep(2); } main(){ int i = 0; signal(SIGINT, routine); signal(SIGHUP, routine); while(1){ printf("%d \n", i++); } }
As you can see, it simply counts from 0 on an infinite loop. Then, by using kill -SIGINT on the process it created, I got the following:
As you can see, before the line I requested the routine to print, the program repeated the last number (and it does not happen always). I would really like to know why.