Skip to content

Instantly share code, notes, and snippets.

@Dunedan
Last active March 24, 2017 17:52
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 Dunedan/698648b86298ee15900f to your computer and use it in GitHub Desktop.
Save Dunedan/698648b86298ee15900f to your computer and use it in GitHub Desktop.
Executes the command provided as argument and respawns it if it got terminated.
#!/bin/sh
# Executes the command provided as argument and respawns it if it got
# terminated.
#
# Licensed under CC0 <https://creativecommons.org/publicdomain/zero/1.0/>
$@ &
PID=$!
while :
do
sleep 1
if ! ps -p $PID > /dev/null; then
$@ &
PID=$!
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment