Skip to content

Instantly share code, notes, and snippets.

@MaikuMori
Created April 15, 2014 15:23
Show Gist options
  • Save MaikuMori/10741317 to your computer and use it in GitHub Desktop.
Save MaikuMori/10741317 to your computer and use it in GitHub Desktop.
Fix upstart stop hang when you've wrongly used `expect fork` or `expect daemon`
#!/bin/bash
sleep 0.0000001 &
firstPID=$!
#first lets exhaust the space
while (( $! >= $firstPID ))
do
sleep 0.000001 &
done
# [ will use testPID itself, we want to use the next pid
declare -i testPID
testPID=$(($1 - 1))
while (( $! < $testPID ))
do
sleep 0.0000001 &
done
# fork a background process then die so init reaps its pid
sleep 3 &
echo "Init will reap PID=$!"
kill -9 $$
# EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment