about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCharadon <dev@iotib.net>2022-08-10 00:57:13 -0400
committerCharadon <dev@iotib.net>2022-08-10 00:57:13 -0400
commit906afa4bdb6c2cf1980311a4f771a5af872d04b5 (patch)
tree9b683ae03953cb918728184695c409cd170394ad
parent6bf6ff6957413aa08fc62baf6646f2e96ea1aa82 (diff)
downloaddscip-906afa4bdb6c2cf1980311a4f771a5af872d04b5.tar.gz
Hopefully solved the locking once and for all
-rwxr-xr-xdscip17
1 files changed, 8 insertions, 9 deletions
diff --git a/dscip b/dscip
index 99915ee..520a169 100755
--- a/dscip
+++ b/dscip
@@ -55,19 +55,18 @@ set -u
 if [ -f "$WORKING_DIRECTORY/LOCK" ]; then
 	LOCKED_PID=$(cat "$WORKING_DIRECTORY/LOCK")
 	# shellcheck disable=SC2009
-	if ps -aux | grep -w "[^]]$LOCKED_PID" > /dev/null; then
-		echo "Script still running. Exiting..."
-		exit 0
-	else
-		echo "Script not running, resetting lock..."
-		rm "$WORKING_DIRECTORY/LOCK"
-	fi
+	for i in $(pgrep -f "$0"); do
+		if [ "$i" = "$LOCKED_PID" ]; then
+			echo "Script still running. Exiting..."
+			exit 0
+		fi
+	done
+	echo "Script not running. Removing old lock."
+	rm -f "$WORKING_DIRECTORY/LOCK"
 fi
 
 echo "$$" > "$WORKING_DIRECTORY/LOCK"
 
-
-
 build () {
 	# Remove old output
 	rm -f "$WORKING_DIRECTORY"/output.txt