0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

シェルスクリプトで呼び出し元プロセスの情報を表示する

Posted at

シェルスクリプトで呼び出し元プロセスの情報を表示する

やり方

子プロセス内で以下で取得できる。

ps $PPID | tail -n 1 | awk '{c="";for(i=5;i<=NF;i++) c=c $i" "; print c}'

スクリプト定義

parent.sh (親プロセス側)

# !/bin/sh

./child.sh test1 test2 test3

child.sh (子プロセス側)

# !/bin/sh

echo $*
ps $PPID | tail -n 1
ps $PPID | tail -n 1 | awk '{c="";for(i=5;i<=NF;i++) c=c $i" "; print c}'

実行例

$ ./parent.sh test test2 test3 test4
test1 test2 test3
3070289 pts/8    S+     0:00 /bin/sh ./parent.sh test test2 test3 test4
/bin/sh ./parent.sh test test2 test3 test4

参考情報

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?