Skip to content

Instantly share code, notes, and snippets.

@shaiguitar
Created June 17, 2011 20:20
Show Gist options
  • Save shaiguitar/1032229 to your computer and use it in GitHub Desktop.
Save shaiguitar/1032229 to your computer and use it in GitHub Desktop.
check processes with kill -0
usage()
{
echo "./$0 [--verbose]"
}
VERBOSE=0
if [ "$1" == "--verbose" ]; then
VERBOSE=1
fi
max_pid_num=$(cat /proc/sys/kernel/pid_max)
for ((i=1;i<$max_pid_num;i++)) ; do
kill -0 $i 2>/dev/null
ret=$?
if [ $ret -eq 0 ]; then
is_reported_in_proc=$(ls -d /proc/$i)
if [ "$is_reported_in_proc" = "" ] ; then
#problem, check this PID.
echo -e "\e[01;31mPROBLEM\e[0m"
echo "kill reported process $i $(ps $i |awk '$1!="PID"') to be running, but it does not show in proc!"
else
if [ $VERBOSE -eq 1 ]; then
echo "Process $i $(ps $i |awk '$1!="PID"') running. exe:$( ls -l /proc/$i/exe 2>/dev/null | awk '{print $10}')"
fi
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment