获取在后台执行的函数的 pid

Get pid of function executed in background

是否可以从函数本身获取后台执行函数的PID?

#!/bin/bash

Foo()
{
  echo PId=$$ #I want pid of process that executed the function!
}

echo Main PID=$$


Foo &  #execute function in background
echo SUBPID=$! #get the pid of last executed background process, in this case Foo

wait

我想你想要这个:

Foo()
{
   echo $PPID # pid of process that executed the function
}