-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlauncher.sh
executable file
·68 lines (54 loc) · 1.38 KB
/
launcher.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#parameters are the names of the processes to be launched
PROCESSES=("$@")
echo ${PROCESSES[@]}
#Killing old processes before starting new ones
commit_hits () {
#file name for old processes to be killed
hitlist=hitlist.txt
#skip if does not exist
if [ -f $hitlist ]; then
echo ""
echo "KILLING PROCESSES"
#And while there are lines to be red...
while read line
do
#Kill the process indicated by the line
killall $line &> /dev/null
done < $hitlist
fi
}
commit_hits
#And finally remove the old hit list before new one is generated
rm $hitlist &> /dev/null
#run the cleaner before processes: it is mandatory
./cleaner
echo ""
echo "LAUNCHING NEW PROCESSES"
echo ""
#launch the proceses in parallel
j=0
for name in "${PROCESSES[@]}"
do
#launch the process
./$name &
#read its pid
mypid=$!
#mark it to the hitlist so that it will be killed before next launch
echo "$name" >> $hitlist
#add to the list of launched processes
pids=$pids"$mypid "
#increase the index
j=`expr $j + 1`
done
#initialize the trap to commit hits when needed
trap "commit_hits" SIGTSTP
echo ""
echo "PROCESSES LAUNCHED"
echo ""
#wait for the processes until they are finished or terminated
wait $pids
echo ""
echo "DONE"
echo ""
#rerun the cleaner in case the resources need to be freed
./cleaner