Skip to content

Instantly share code, notes, and snippets.

@JayGoldberg
Last active April 11, 2017 14:50
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 JayGoldberg/7f90294ae1c780c994897f054f7c3af2 to your computer and use it in GitHub Desktop.
Save JayGoldberg/7f90294ae1c780c994897f054f7c3af2 to your computer and use it in GitHub Desktop.
A reimplementation of `pgrep` in shell
#!/bin/sh
## @author Jay Goldberg
## @email jaymgoldberg@gmail.com
## @license Apache 2.0
## @description Implement pgrep on platforms that don't have it
## @usage source it, then pgrep <processname>
#=======================================================================
pgrep() {
for pid in /proc/[0-9]*; do
cat ${pid}/cmdline | tr '\000' ' '| grep "$1" &> /dev/null
[ "$?" -eq 0 ] && echo $(basename $pid)
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment