aha364636
aha364636

Reputation: 363

Killall doesn't work if I call it from a bash script

I'm starting a tcpdump inside a script and I also kill it from the same script. So I'm currently using the killall command for this: The script gets executed from an udev rule: This is the section, which should terminate the tcpdump: In addition I also use -s SIDKILL, because I've read that this could also help.

What is the problem that killall doesn't terminate the tcpdump. When I start the script manually it is all working properly.

 if [[ "$pid1" != "" ]];then
          sudo killall -s SIGKILL tcpdump
          sh /tmp/scripts/autoumount.sh &
          sudo kill -9 $$
          echo "autodump stopped"

Upvotes: 0

Views: 1271

Answers (1)

Charles Duffy
Charles Duffy

Reputation: 295629

Since you're starting tcpdump from the same script, there's no need for killall.

If you're running multiple background processes, use an array, like so:

pids=( )                 # initialize empty array
tcpdump & pids+=( "$!" ) # extend said array

...later on, you can kill those PIDs:

kill "${pids[@]}"

Upvotes: 2

Related Questions