automatic start/stop through signal

Hi!
In the latest project I’ve been working on needs to be started at certain time and to be stopped in the afternoon. We made a script that runs from crontab that makes the work fine stopping the app with kill . The problem is that when the application exits it needs to run the exit() method of the oF application to save some data , and when the app is stopped with kill the exit() method is not called.

¿Is there a signal num that exits the application in not a such “dirty” way?
¿is there a better way to schedule when the application has to start and when it has to stop?
thnakyouthankyou

I think what you need is a signal handler. That’s a C routine that you can use to trap signals.

There’s an example here to trap CTRL-C :
http://www.metalshell.com/source-code/1-…-ignal.html

For a Kill signal, you would use SIGKILL instead of SIGINT. At least, I think this should work. Then you could clean stuff up in the signal handler before exiting.

catching the signal was something I didn’t wanted to do, but it was much easier that how I remembered it. Here is my code, it might be useful for someone.
If there is any suggestion please tell me
main.cpp

  
  
#include "ofMain.h"  
#include "testApp.h"  
#include "ofAppGlutWindow.h"  
#include <signal.h>  
//========================================================================  
void handler( int signal ) {  
  exit(0); //this makes it to exit in a "clean" way  
}  
  
int main( ){  
    ofAppGlutWindow window;  
	ofSetupOpenGL(&window, 512,512, OF_WINDOW);			// <-------- setup the GL context  
  
	// this kicks off the running of my app  
	// can be OF_WINDOW or OF_FULLSCREEN  
	// pass in width and height too:  
  
    signal(SIGQUIT, handler );  
	ofRunApp(new testApp());  
}  
  

to exit the app from shell with kill
kill -3