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
精彩评论