Skip to content

Instantly share code, notes, and snippets.

@frace
Forked from vgrichina/pidof
Created November 27, 2012 20:13
Show Gist options
  • Select an option

  • Save frace/4156720 to your computer and use it in GitHub Desktop.

Select an option

Save frace/4156720 to your computer and use it in GitHub Desktop.
pidof for OS X
#!/usr/bin/env bash
if (( $# == 1 )); then
declare proc="$(ps axc | grep "$1")"
read -ra pid <<< "$proc"
if (( $pid )); then
echo $pid
exit 0
else
exit 1
fi
else
echo "Usage: $0 <processname>"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment