Skip to content

Instantly share code, notes, and snippets.

@jjb
Last active January 22, 2022 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjb/554bc3fb70d6bfb5544e75ce49b1b50b to your computer and use it in GitHub Desktop.
Save jjb/554bc3fb70d6bfb5544e75ce49b1b50b to your computer and use it in GitHub Desktop.
single-line process restarter without systemd

example program being monitored - sleep.sh

while [ 1 ]
do
  sleep 1
  echo hello
done

the invocation

while true; do sh sleep.sh; echo 'sleep.sh has crashed, restarting'; sleep 1; done

try it out

terminal 1

run the invocation

terminal 2

  1. ps | grep sleep.sh, find the pid of the running sh sleep.sh
  2. kill 123
  3. observe the "monitor" announce the restart and the series of "hello" start up again
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment