The signal to gracefully terminate an application is SIGTERM
(signal number 15) - and a forceful kill is SIGKILL
(signal number 9).
Alternatively, for some applications you could use SIGHUP
(signal number 1), to restart the application and reload the config.
So the basic command would look like:
kill -s 15 -p <PID>
One way to find the PID
of the process is to use pgrep
- or you could use the combined command pkill
, which finds using pgrep
and then sends a signal (SIGTERM
by default).
If you were to kill htop
(doesn't really make sense, but just as an example) and start it again, the script commands would be: (run as root)
# pkill sends signal 15 as default
pkill htop
# start htop again
htop
Or in case a SIGHUP
is enough:
# tell pkill to send signal 1 instead
pkill -s 1 htop
Even another option would be to use the killall
command, which also sends signals by process name.
Also see man pages:
And finally see additional info here.