Reputation: 356
I have an existing "command line tool" project. This tool runs forever until user close terminal. There is not any method which will be called when application will terminate. How can I set a applicationWillTerminate like delegate method in this project. The need is to receive notification when user click close on terminal window.
Also is there any way to get notification when user exit the command by pressing CTRL+C?
Upvotes: 2
Views: 355
Reputation: 21912
You should be able to trap the signals from Unix.
signal(SIGABRT, SignalHandler);
signal(SIGILL, SignalHandler);
signal(SIGSEGV, SignalHandler);
signal(SIGFPE, SignalHandler);
signal(SIGBUS, SignalHandler);
signal(SIGPIPE, SignalHandler);
Then define a signal handler: void SignalHandler(int signum) { ... }
Here's an example.
Also you can read on signal handling, it should help. This might also be useful even though it's for iOS.
Upvotes: 4