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.

#7

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-05 10:51:36 -05:00
parent a491ae4592
commit 86be5fd1c1

View File

@@ -128,6 +128,24 @@ get_disk_list() {
echo "$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 # System Information Functions
################### ###################