2014-11-02 52 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