Last active
April 11, 2017 14:50
-
-
Save JayGoldberg/7f90294ae1c780c994897f054f7c3af2 to your computer and use it in GitHub Desktop.
A reimplementation of `pgrep` in shell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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