Should a service cancel and terminate incomplete work on SIGTERM

signals

Assuming that service does not leave things in "dangerous" or inconsistent state (though failures to carry tasks will be observed), should it close files, connections and any other work?

Best Answer

Yes it should. If it does or not is up to the utility.

Files and connections are usually closed when a program exits for whatever reason, however "other work" may be left half-done (temporary files may be left behind, databases may possibly be in a questionable state, data actually not written to files will be lost etc.)

A program may catch the TERM signal in a signal handler and exit gracefully, i.e. finish off anything it was doing and leave the world in an orderly state upon actual termination. It may also catch and ignore the signal completely.

Related Question