dcaa58b4498fabe25276ab3a1091e8cacf68aa91
[vpp.git] / test / scripts / run_with_cleanup.sh
1 #!/bin/bash
2
3 rv=0
4
5 atexit() {
6         group_id=`ps -p $$ -o pgid=`
7         my_id=$$
8         ids=`pgrep -g $group_id -d ' ' | sed "s/\b$my_id\b//g"`
9         echo "Killing possible remaining process IDs: $ids"
10         for id in $ids
11         do
12                 if ps -p $id > /dev/null
13                 then
14                         kill -9 $id
15                 fi
16         done
17         exit $rv
18 }
19
20 trap "atexit" SIGINT SIGTERM
21
22 $*
23 rv=$?
24 atexit
25 exit $rv