Skip to content
Snippets Groups Projects
Commit 0061751e authored by Carmelo Pellegrino's avatar Carmelo Pellegrino
Browse files

clean-up implemented through trap on exit

parent c0cf07e8
No related branches found
No related tags found
No related merge requests found
...@@ -24,6 +24,16 @@ function test_lock() { ...@@ -24,6 +24,16 @@ function test_lock() {
fi fi
} }
function on_exit() {
if [ "${LOCK_OWNER}" == "True" ]; then
rm_lock
fi
for pid in ${PROCS}; do
kill -9 ${pid}
done
}
function createList() { function createList() {
local LIST local LIST
local file local file
...@@ -73,6 +83,9 @@ function get_run_number() { ...@@ -73,6 +83,9 @@ function get_run_number() {
test_lock || { zenity --error --text="There is another instance running of this program."; exit 1;} test_lock || { zenity --error --text="There is another instance running of this program."; exit 1;}
put_lock put_lock
LOCK_OWNER="True"
trap on_exit EXIT
while [ 1 ]; do while [ 1 ]; do
...@@ -88,7 +101,6 @@ while [ 1 ]; do ...@@ -88,7 +101,6 @@ while [ 1 ]; do
if [ -z "${rs_file}" ]; then if [ -z "${rs_file}" ]; then
zenity --error --text="No Run Setup file selectet, aborting" zenity --error --text="No Run Setup file selectet, aborting"
rm_lock
exit -1 exit -1
fi fi
...@@ -125,6 +137,7 @@ run_number=`get_run_number` ...@@ -125,6 +137,7 @@ run_number=`get_run_number`
daq_log_file=~/.km3_private/daq_${run_number}.log daq_log_file=~/.km3_private/daq_${run_number}.log
JGetMessage -H localhost -T MSG -d 3 >${daq_log_file} & JGetMessage -H localhost -T MSG -d 3 >${daq_log_file} &
PROCS=(${PROCS} $!)
## impl: get the pid and add to the list of must_kill_at_the_exit ## impl: get the pid and add to the list of must_kill_at_the_exit
# Copy selected run setup file, changing the run number # Copy selected run setup file, changing the run number
...@@ -134,6 +147,7 @@ run_start_time=`nowUTC` ...@@ -134,6 +147,7 @@ run_start_time=`nowUTC`
# Launch the DM # Launch the DM
dm_driver ${run_duration} | mono DetectorControl.exe --control --reset & dm_driver ${run_duration} | mono DetectorControl.exe --control --reset &
PROCS=(${PROCS} $!)
# Launch the DAQ # Launch the DAQ
log "Launching the DAQ with the following command line: daq.sh ${run_number} ${run_start_time} ${run_duration}" log "Launching the DAQ with the following command line: daq.sh ${run_number} ${run_start_time} ${run_duration}"
...@@ -149,6 +163,4 @@ sleep ${run_duration} ...@@ -149,6 +163,4 @@ sleep ${run_duration}
zenity --info --text="Run ${run_number} finished!" zenity --info --text="Run ${run_number} finished!"
rm_lock
exit 0 exit 0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment