How can I get pid of a subprocess from the subprocess itself?    foo(){ echo pid=$$ echo spid=$! echo bpid=$BASHPID}echo PARENT_PID=$$foo &waiton first run I get:PARENT_PID=17112[1]     17512pid=17112spid=bpid=I expect to see spid 17512On second run I get something strange:PARENT_PID=17112[1]     17797pid=17112spid=17512 #why I see here pid of previous subprocess???bpid=I expect to see 17797 but getting 17512 !!so 2 questions:1)how to get the pid of sub process from inside of it (I will execute Foo multiple times and expect to see pid of every subprocess)?2)why I am getting the unexpected result of second run?
How to get pid of subprocess from the subprocess itself
bash;process