プロセスIDに関するシェル変数

スポンサーリンク
スポンサーリンク

Linux でのプロセスIDに関するシェル変数です

$$:現在のシェルのプロセスID
$!:最後に起動したバックグラウンドプロセスのプロセスID

実行例です。

test.sh

./tp &
ps
echo The PID of the current shell is $$.
echo The PID of the last backgrounded process is $!.

$ sh ./test.sh
  PID TTY          TIME CMD
 1778 pts/0    00:00:00 bash
 1830 pts/0    00:00:00 sh
 1831 pts/0    00:00:00 tp
 1832 pts/0    00:00:00 ps
The PID of the current shell is 1830.
The PID of the last backgrounded process is 1831.

参考

linux – get pid in shell (bash) – Stack Overflow

コメント

タイトルとURLをコピーしました