2016-04-28 60 views
0

是否有可能從函數本身獲取在後臺執行的函數的PID?獲取在後臺執行的函數的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

我想你想要這樣的:

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