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:
18
proxDoc.sh
18
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
|
||||
###################
|
||||
|
||||
Reference in New Issue
Block a user