From 030d44d14007e590fc097acf1168ba51168843b7 Mon Sep 17 00:00:00 2001 From: Ken Soh Date: Fri, 28 Jun 2019 14:47:01 +0800 Subject: [PATCH] #466 / #417 - shell script to kill TagUI processes Follow-up update to previous 3 commits below by improving to remove Linux warning message - Making a commit to improve on the existing script to kill TagUI processes. For eg if Ctrl+C is used to kill TagUI prematurely, TagUI main process would lose the control to do clean-up of integrations (SikuliX, R, Python, Chrome) and Chrome browser. This shell script (for all the 3 OSes) will kill those processes to free up memory and allows TagUI to start running from a clean state. These actions are not done by default when TagUI is launched, as it is expected that TagUI exits cleanly. Otherwise cleaning up all processes by default will hide potential issues should they arise and they will end up not getting reported. --- src/end_processes | 12 ++++++------ src/tagui | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/end_processes b/src/end_processes index 69e6097e..f08adb16 100755 --- a/src/end_processes +++ b/src/end_processes @@ -5,7 +5,7 @@ # works by scanning processes for tagui keywords and killing them one by one while true; do - php_process_id="$(ps -x | grep tagui_chrome\.php | grep -v 'grep tagui_chrome\.php' | sed -e 's/^[ ]*//' | cut -d' ' -f 1 | sort -nur | head -n 1)" + php_process_id="$(ps x | grep tagui_chrome\.php | grep -v 'grep tagui_chrome\.php' | sed -e 's/^[ ]*//' | cut -d' ' -f 1 | sort -nur | head -n 1)" if [ -n "$php_process_id" ]; then kill $php_process_id > /dev/null 2>&1 else @@ -14,7 +14,7 @@ while true; do done while true; do - chrome_process_id="$(ps -x | grep remote-debugging-port=9222 | grep tagui_user_profile | sed -e 's/^[ ]*//' | cut -d' ' -f 1 | sort -nur | head -n 1)" + chrome_process_id="$(ps x | grep remote-debugging-port=9222 | grep tagui_user_profile | sed -e 's/^[ ]*//' | cut -d' ' -f 1 | sort -nur | head -n 1)" if [ -n "$chrome_process_id" ]; then kill $chrome_process_id > /dev/null 2>&1 else @@ -23,7 +23,7 @@ while true; do done while true; do - sikuli_process_id="$(ps -x | grep tagui\.sikuli | grep -v 'grep tagui\.sikuli' | sed -e 's/^[ ]*//' | cut -d' ' -f 1 | sort -nur | head -n 1)" + sikuli_process_id="$(ps x | grep tagui\.sikuli | grep -v 'grep tagui\.sikuli' | sed -e 's/^[ ]*//' | cut -d' ' -f 1 | sort -nur | head -n 1)" if [ -n "$sikuli_process_id" ]; then kill $sikuli_process_id > /dev/null 2>&1 else @@ -32,7 +32,7 @@ while true; do done while true; do - python_process_id="$(ps -x | grep tagui_py\.py | grep -v 'grep tagui_py\.py' | sed -e 's/^[ ]*//' | cut -d' ' -f 1 | sort -nur | head -n 1)" + python_process_id="$(ps x | grep tagui_py\.py | grep -v 'grep tagui_py\.py' | sed -e 's/^[ ]*//' | cut -d' ' -f 1 | sort -nur | head -n 1)" if [ -n "$python_process_id" ]; then kill $python_process_id > /dev/null 2>&1 else @@ -41,7 +41,7 @@ while true; do done while true; do - r_process_id="$(ps -x | grep tagui_r\.R | grep -v 'grep tagui_r\.R' | sed -e 's/^[ ]*//' | cut -d' ' -f 1 | sort -nur | head -n 1)" + r_process_id="$(ps x | grep tagui_r\.R | grep -v 'grep tagui_r\.R' | sed -e 's/^[ ]*//' | cut -d' ' -f 1 | sort -nur | head -n 1)" if [ -n "$r_process_id" ]; then kill $r_process_id > /dev/null 2>&1 else @@ -50,7 +50,7 @@ while true; do done while true; do - tagui_process_id="$(ps -x | grep tagui/src | grep -v 'grep tagui/src' | grep -v 'end_processes' | sed -e 's/^[ ]*//' | cut -d' ' -f 1 | sort -nur | head -n 1)" + tagui_process_id="$(ps x | grep tagui/src/ | grep -v 'grep tagui/src/' | grep -v 'end_processes' | sed -e 's/^[ ]*//' | cut -d' ' -f 1 | sort -nur | head -n 1)" if [ -n "$tagui_process_id" ]; then kill $tagui_process_id > /dev/null 2>&1 else diff --git a/src/tagui b/src/tagui index 9018821c..3263dbd7 100755 --- a/src/tagui +++ b/src/tagui @@ -297,14 +297,14 @@ if [ "$chrome_started" == "Darwin" ]; then if ! [ -f "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" ]; then echo "ERROR - cannot find Chrome at \"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome\"" echo "Chrome is at a non-standard location on your macOS, raise an issue on TagUI GitHub page"; exit 1; fi -chrome_process_id="$(ps -x | grep remote-debugging-port=9222 | grep tagui_user_profile | sed -e 's/^[ ]*//' | cut -d' ' -f 1 | sort -nur | head -n 1)" +chrome_process_id="$(ps x | grep remote-debugging-port=9222 | grep tagui_user_profile | sed -e 's/^[ ]*//' | cut -d' ' -f 1 | sort -nur | head -n 1)" if [ -n "$chrome_process_id" ]; then kill $chrome_process_id; fi /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome $chrome_switches $window_size $headless_switch > /dev/null 2>&1 & else if ! type "$chrome_command" > /dev/null; then echo "ERROR - cannot find Chrome command \"$chrome_command\"" echo "update chrome_command setting in tagui/src/tagui and make sure symlink to command is created"; exit 1; fi -chrome_process_id="$(ps -x | grep remote-debugging-port=9222 | grep tagui_user_profile | sed -e 's/^[ ]*//' | cut -d' ' -f 1 | sort -nur | head -n 1)" +chrome_process_id="$(ps x | grep remote-debugging-port=9222 | grep tagui_user_profile | sed -e 's/^[ ]*//' | cut -d' ' -f 1 | sort -nur | head -n 1)" if [ -n "$chrome_process_id" ]; then kill $chrome_process_id; fi $chrome_command $chrome_switches $window_size $headless_switch > /dev/null 2>&1 & fi @@ -334,10 +334,10 @@ if [ -f "tagui_chrome.in" ]; then echo "finish" > tagui_chrome.in; fi # kill chrome processes by checking which os the processes are started on if [ "$chrome_started" == "Darwin" ] && [ "$tagui_speed_mode" == false ]; then -chrome_process_id="$(ps -x | grep remote-debugging-port=9222 | grep tagui_user_profile | sed -e 's/^[ ]*//' | cut -d' ' -f 1 | sort -nur | head -n 1)" +chrome_process_id="$(ps x | grep remote-debugging-port=9222 | grep tagui_user_profile | sed -e 's/^[ ]*//' | cut -d' ' -f 1 | sort -nur | head -n 1)" if [ -n "$chrome_process_id" ]; then kill $chrome_process_id; fi else if [ -n "$chrome_started" ] && [ "$tagui_speed_mode" == false ]; then -chrome_process_id="$(ps -x | grep remote-debugging-port=9222 | grep tagui_user_profile | sed -e 's/^[ ]*//' | cut -d' ' -f 1 | sort -nur | head -n 1)" +chrome_process_id="$(ps x | grep remote-debugging-port=9222 | grep tagui_user_profile | sed -e 's/^[ ]*//' | cut -d' ' -f 1 | sort -nur | head -n 1)" if [ -n "$chrome_process_id" ]; then kill $chrome_process_id; fi fi; fi