开发者

in a sh script, get the pid of a background process

Is it possible to know the pid of the iwevent process in the following bash script:

#!/bin/sh
( iwevent | logger -t IWEVENT ) &
echo the pid is: ???

Note that iwevent run until ctrl-c signal.

FYI. I run this script in a /etc/network/interfaces "up"开发者_运维技巧 statement and I want to kill the running iwevent process in the related "down" statement. My aim is to log wireless events.


Something like this should do the trick:

#!/bin/sh
( { iwevent & printf "The pid is %s\n" $! >&3; } | logger -t IWEVENT ) 3>&1 &

If you need it in a variable, read the output of the above.


check "pidof" function
see this http://en.wikipedia.org/wiki/Pidof
and check the man page: man pidof

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜