#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:¶
-
Type: Cleanup
-
Impact: Low
-
Reference to related issue (URL):
https://github.com/rear/rear/issues/2089#issuecomment-476590268 -
How was this pull request tested?
By me on my openSUSE Leap 15.0 system as in
https://github.com/rear/rear/pull/2088#issuecomment-474446764
and subsequent comments. -
Brief description of the changes in this pull request:
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.]