In bash you have this handy variable: $BASHPID wich always returns the currently running subshell's PID. How can I get a subshell's PID in ksh? For example see the code below:
#!/usr/bin/ksh93
echo "PID at start: $$"
function run_in_background {
echo "PID in run_in_background $$"
run_something &
echo "PID of backgrounded run_something: $!"
}
function run_something {
echo "*** PID in run_something: $$"
sleep 10;
}
run_in_background
echo "PID of run in background $!"
This outputs the following:
PID at start: 5328
PID in run_in_background 5328
*** PID in run_something: 5328
PID of backgrounded run_something: 5329
PID of run in background 5329
What I want is the line starting with **** to output the subshell's PID, in the example's case that would be 5329.