#2099 PR merged: Use simplest way to get current PID in bash 3 (related to issue 2089)

Labels: cleanup, fixed / solved / done

jsmeix opened issue at 2019-03-26 11:46:

A SUSE colleague found the simplest way to get the current PID
without using bsh 4.x $BASHPID:

read current_pid junk </proc/self/stat

This also works even in nested subshells in a sourced script
and it is simpler than what I had used before

tmpfile=$( mktemp )
cat /proc/self/stat >$tmpfile
current_pid=$( cut -d ' ' -f4 $tmpfile )
rm $tmpfile

because read is a shell builtin (so no parent PID stuff is needed)
and the < stdin redirection does not cause another subshell.

jsmeix commented at 2019-03-26 12:58:

When there are no objections I would like to merge it soon today.


[Export of Github issue for rear/rear.]