What's the difference between the SIGINT
signal and the SIGTERM
signal? I know that SIGINT
is equivalent to pressing Ctrl+C on the keyboard, but what is SIGTERM
for? If I wanted to stop some background process gracefully, which of these should I use?
The only difference in the response is up to the developer. If the developer wants the application to respond to SIGTERM
differently than to SIGINT
, then different handlers will be registered. If you want to stop a background process gracefully, you would typically send SIGTERM
. If you are developing an application, you should respond to SIGTERM
by exiting gracefully. SIGINT
is often handled the same way, but not always. For example, it is often convenient to respond to SIGINT
by reporting status or partial computation. This makes it easy for the user running the application on a terminal to get partial results, but slightly more difficult to terminate the program since it generally requires the user to open another shell and send a SIGTERM
via kill
. In other words, it depends on the application but the convention is to respond to SIGTERM
by shutting down gracefully, the default action for both signals is termination, and most applications respond to SIGINT
by stopping gracefully.