I'm trying to get the PID of tcpdump
which is part of a while loop. Example:
tcpdump -x -q -l -i $IFACE port $PORT | while read buffer; do
# process, if something received from tcpdump. Otherwise wait
done
$!
within the while loop will not provide the PID of tcpdump
.
How to get the PID of tcpdump
in this construct?
kill -9 PID_of_script
, tcpdump hangs independently in the process list. So, I assume tcpdump is still listening. For that reason I have a trap installed which will kill the tcpdump. But for that I need the PID of tcpdump. For sure I could get the PID by using ps - ef|grep tcpdump, but I think there is a more elegant way to do it. – autio Aug 02 '17 at 08:51