Skip to content

Instantly share code, notes, and snippets.

@kacinskas
Created September 24, 2012 12:26
Show Gist options
  • Save kacinskas/3775701 to your computer and use it in GitHub Desktop.
Save kacinskas/3775701 to your computer and use it in GitHub Desktop.
LINUX: get PID
#!/bin/sh
SERVICE='EldesDaemon'
FILE='/usr/local/sbin/eldes/EldesDaemon.pid'
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
#PIDID=$(ps ax | grep -v grep | grep $SERVICE | awk '{print $1}')
#echo "$SERVICE service running, everything is fine"
#echo "pid = $PIDID"
#echo $PIDID > $FILE
if [ -f $FILE ];
then
echo "File $FILE exists"
while read line
do
PIDID=${line%,*}
echo $PIDID
done < $FILE
kill -9 $PIDID
else
echo "File $FILE does not exist"
fi
else
echo "$SERVICE is not running"
fi
@sKwa
Copy link

sKwa commented Jan 6, 2015

Hi!

Looks like bugs/mistakes migrates from one user to other. Does no one aware about pidof? In 99,999% cases I see: ps x | grep .... Are you aware about pidof?
::

daniel@synapse:~/Documents/Vertica$ ps x | grep [f]irefox
 2521 ?        Sl    39:31 /usr/lib/firefox/firefox
 5184 ?        Rl    15:39 /usr/lib/firefox/plugin-container /usr/lib/flashplugin-installer/libflashplayer.so -greomni /usr/lib/firefox/omni.ja -appomni /usr/lib/firefox/browser/omni.ja -appdir /usr/lib/firefox/browser 2521 true plugin
daniel@synapse:~/Documents/Vertica$ pidof firefox
2521

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment