diff --git a/rsselector.sh b/rsselector.sh
index c6ba09f339575d8f699a1b020c02dc928d6127f8..96aaf65b64790cac564f7b488403c7d197622bda 100644
--- a/rsselector.sh
+++ b/rsselector.sh
@@ -16,7 +16,11 @@ function rm_lock() {
 }
 
 function test_lock() {
-  return [ -e /tmp/auto_ss ]
+  if [ -e /tmp/auto_ss ]; then
+    return 1
+  else
+    return 0
+  fi
 }
 
 function createList() {
@@ -64,6 +68,11 @@ function get_run_number() {
   echo ${run_number}
 }
 
+
+test_lock || { zenity --error --text="There is another instance running of this program."; exit 1;}
+
+put_lock
+
 while [ 1 ]; do
 
   # Ask for the run setup
@@ -138,4 +147,6 @@ sleep ${run_duration}
 
 zenity --info --text="Run ${run_number} finished!"
 
+rm_lock
+
 exit 0