blob: 35b6737ecad9eab7bdb1dca526905bb6b36af401 [file] [log] [blame]
Klement Sekera94384e42017-07-11 07:29:37 +02001#!/bin/bash
2
3rv=0
4
5atexit() {
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
Klement Sekera8712ada2017-08-16 16:38:10 +020017 exit ${rv}
Klement Sekera94384e42017-07-11 07:29:37 +020018}
19
Klement Sekeradb4e84c2017-08-11 10:06:15 +020020trap "atexit;" SIGINT SIGTERM
Klement Sekera94384e42017-07-11 07:29:37 +020021
Klement Sekeradb4e84c2017-08-11 10:06:15 +020022FORCE_FOREGROUND=$1
23shift
24
25source $1
26shift
27
28if [[ "${FORCE_FOREGROUND}" == "1" ]]
29then
30 $*
31else
32 $* &
Klement Sekera8712ada2017-08-16 16:38:10 +020033 pid=$!
34 wait ${pid}
Klement Sekeradb4e84c2017-08-11 10:06:15 +020035fi
36
Klement Sekera94384e42017-07-11 07:29:37 +020037rv=$?
38atexit
Klement Sekera8712ada2017-08-16 16:38:10 +020039exit ${rv}