From 86be5fd1c13612c0fa8119bc1a30f38ba7ba5524 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Thu, 5 Feb 2026 10:51:36 -0500 Subject: [PATCH] Add efficient process wait utility function Add wait_for_process() that uses kill -0 instead of ps -p for checking if a process is running. This is more efficient as kill -0 only checks process existence without spawning a new process like ps would. Includes optional spinner for visual feedback during waits. https://code.lotusguild.org/LotusGuild/proxDoc/issues/7 Co-Authored-By: Claude Opus 4.5 --- proxDoc.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/proxDoc.sh b/proxDoc.sh index 2f4af97..c578442 100755 --- a/proxDoc.sh +++ b/proxDoc.sh @@ -128,6 +128,24 @@ get_disk_list() { echo "$DISK_LIST" } +# Efficient process wait with optional spinner +# Usage: wait_for_process $pid [delay] +# Uses kill -0 instead of ps -p for efficiency +wait_for_process() { + local pid="$1" + local delay="${2:-0.1}" + local spinner='|/-\' + local i=0 + + while kill -0 "$pid" 2>/dev/null; do + printf "\r%c " "${spinner:i++%${#spinner}:1}" + sleep "$delay" + done + printf "\r \r" # Clear spinner + wait "$pid" + return $? +} + ################### # System Information Functions ###################