Skip to content

Instantly share code, notes, and snippets.

@ormaaj
Created February 5, 2013 10:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ormaaj/4713524 to your computer and use it in GitHub Desktop.
Save ormaaj/4713524 to your computer and use it in GitHub Desktop.
BASHPID
if [[ ${!KSH_VERSION} == .sh.version ]]; then
if builtin pids 2>/dev/null; then
function BASHPID.get { .sh.value=$(pids -f '%(pid)d'); }
elif [[ -r /proc/self/stat ]]; then
function BASHPID.get { read -r .sh.value _ </proc/self/stat; }
else
function BASHPID.get { .sh.value=$(exec sh -c 'echo $PPID'); }
fi
elif [[ ! ${BASHPID+_} ]]; then
echo 'BASHPID requires Bash, ksh93, or mksh >= R41' >&2
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment