title: How to have Linux wait till my program finishes its SIGTERM action?
body: <p>How to have Linux wait till my C++ program completes its cleanup routine. The program initially calls function <code>sigaction(2)</code> to register a custom SIGTERM handler. If test the handler by running <code>kill -s TERM $(ps -C a.out -o pid=)</code>, it would have no problem. However, in the real shutting down is another case. Sometimes the handler can get its job all done, but sometimes not. Apparently there is a race condition when the machine is shutting down. Does anyone know how to make the system wait a little bit longer so as to avoid the race condition? Thanks.</p>