【问题标题】:Get pid of function executed in background获取后台执行的函数的pid
【发布时间】:2016-04-28 10:18:28
【问题描述】:

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

【问题讨论】:

    标签: bash unix process


    【解决方案1】:

    我想你想要这个:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-04
      • 1970-01-01
      • 2018-01-17
      • 2017-01-23
      • 2011-01-26
      • 1970-01-01
      • 2010-11-05
      相关资源
      最近更新 更多