<div dir="ltr"><div>Sorry for the cross post but this is not an easy question I don't think....</div><div><br></div>Given:<div>Pid of a process is $$</div><div>Pid of a child process just spawned is $!</div><div>However a child process does not see $$ as it's pid but rather the pid of it's parent... How can the child process know it's own pid?</div><div><br></div><div>Example:</div><div><div>[root@mybox l]# cat backTest</div><div>function backGround() {</div><div>        echo "Pid $1 is $$"</div><div>}</div><div>function backGround_subshell() {</div><div>        echo "echo Pid $1 is $$"</div><div>}</div><div>echo "My pid is $$"</div><div>backGround 1 &</div><div>echo "BPid 1 is $!"</div><div>backGround 2 &</div><div>echo "BPid 2 is $!"</div><div>backGround 3 &</div><div>echo "BPid 3 is $!"</div><div>$(backGround_subshell 4) &</div><div>echo "BPid 4 is $!"</div><div>$(backGround_subshell 5) &</div><div>echo "BPid 5 is $!"</div><div>$(backGround_subshell 6) &</div><div>echo "BPid 6 is $!"</div><div>wait</div><div>echo</div><div>[root@mybox l]# bash backTest</div><div>My pid is 16712</div><div>BPid 1 is 16713</div><div>Pid 1 is 16712</div><div>BPid 2 is 16714</div><div>Pid 2 is 16712</div><div>BPid 3 is 16715</div><div>BPid 4 is 16716</div><div>BPid 5 is 16717</div><div>BPid 6 is 16719</div><div>Pid 4 is 16712</div><div>Pid 3 is 16712</div><div>Pid 6 is 16712</div><div>Pid 5 is 16712</div></div><div><br></div></div>