Skip to content

Instantly share code, notes, and snippets.

@biinari
Created February 13, 2015 11:56
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 biinari/4f4df8134d71d6c3236d to your computer and use it in GitHub Desktop.
Save biinari/4f4df8134d71d6c3236d to your computer and use it in GitHub Desktop.
Modified version of https://bugs.launchpad.net/upstart/+bug/406397/comments/47 to work with ubuntu sleep
#!/bin/bash
# usage: bash /tmp/upstart_fix_pid.sh <pid>
sleep 0.001 &
firstPID=$!
# exhaust the pid space
while (( $! >= $firstPID ))
do
sleep 0.001 &
done
# will use up to testPID inclusive, we want to use the next pid
declare -i testPID
testPID=$(($1 - 1))
while (( $! < $testPID ))
do
sleep 0.001 &
done
# fork a background process then die so init reaps its pid
sleep 3 &
echo "Init will reap PID=$!"
kill -9 $$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment