获取后台执行的pid功能

时间:2016-04-28 10:18:29

标签: bash unix process

是否可以从函数本身获取后台执行的函数的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

1 个答案:

答案 0 :(得分:1)

我想你想要这个:

{{1}}