Comment 47 for bug 406397

Revision history for this message
Wade Fitzpatrick (wade-8) wrote :

I had a problem with john miller's bash script because bash didn't die quickly enough for the microsleep to get re-parented by init (upstart), so here is a better version:

#!/bin/bash

usleep 1 &
firstPID=$!
#first lets exhaust the space
while (( $! >= $firstPID ))
do
    usleep 1 &
done

# [ will use testPID itself, we want to use the next pid
declare -i testPID
testPID=$(($1 - 1))
while (( $! < $testPID ))
do
    usleep 1 &
done

# fork a background process then die so init reaps its pid
sleep 3 &
echo "Init will reap PID=$!"
kill -9 $$
# EOF

Example usage:
# sh /tmp/upstart_fix.sh 19915
Init will reap PID=19915
Killed