0

As the title says, I'd like to schedule basically a graceful termination of an app and then have it restarted after the termination. The reason for this is that the app seldomly hangs with no exact pattern. Restarting it once a day would fix this.

Thank you!

1 Answers1

2

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.

Artur Meinild
  • 26,018