Skip to content

Instantly share code, notes, and snippets.

@mem
Created February 3, 2015 19:44
Show Gist options
  • Save mem/7e989639e6204e687987 to your computer and use it in GitHub Desktop.
Save mem/7e989639e6204e687987 to your computer and use it in GitHub Desktop.
Look for process pid by command line without forking
needle=/usr/lib/chromium/chromium
cd /proc
for pid in * ; do
if test -e "$pid/cmdline" ; then
read cmd rest < $pid/cmdline
if test "$cmd" = "$needle" ; then
echo $pid
fi
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment