I frequently run programs that run for several days, testing successive integers for various criteria. I like to know where a program is up to, so I usually have it print out a message every, say, 100000000 trials, but it would be nice if I could get intermediate results by sending the program a signal. The kind of thing I have in mind is something like this:
Create signal handler to print out value of n and resume in loop
Register signal handler
n=1
while( 1 ) {
If n fits some criterion, print n
n++
}
with the idea that I could then use kill -SIGTYPE processid
to get the intermediate results. Is it possible to do what I want? And if so, how? The examples I have seen that use signal handling in C all seem to exit immediately after having dealt with the signal, rather than resuming from the point where the signal was caught.