获取后台执行的函数的pid [英] Get pid of function executed in background
本文介绍了获取后台执行的函数的pid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以从函数本身获取在后台执行的函数的PID?
Is it possible to get PID of function executed in background from the function itself?
#!/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
}
这篇关于获取后台执行的函数的pid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文