2014-11-02 45 views
0
我使用的是试图让进程ID数的bash过程

同一进程ID:中test_run.sh获得多个进程的进程ID返回在bash

 
echo "run $1" 

 
./test_run.sh hello 
echo $$ 
./test_run.sh hellos 
echo $$ 
./test_run.sh hello22 
echo $$ 

定义但他们都返回相同的进程id,为什么?

回答

2

$$返回当前shell进程的PID。要获得刚开始的后台进程的PID,请使用$!

./test_run.sh hello & 
echo $! 
./test_run.sh hello & 
echo $! 
+0

请看更新的问题。 – user121196 2014-11-02 12:31:09

+0

您所做的只是将参数更改为'test_run.sh'。这个问题有什么不同? – Barmar 2014-11-02 22:51:02

+0

$$返回相同的pid和$!在更新的问题中返回“”。我希望$$返回不同的pid – user121196 2014-11-02 23:49:16