increased reliability

This commit is contained in:
fatalerrors
2026-04-15 08:13:17 +02:00
parent 322d03ed4c
commit e5bafe1721

View File

@@ -50,7 +50,27 @@ ppg()
disp E "Usage: ppg <string>" disp E "Usage: ppg <string>"
return 1 return 1
fi fi
ps -edf | grep "$@" | grep -v "grep $@"
local pattern="$*"
if command -v pgrep >/dev/null 2>&1; then
pgrep -af -- "$pattern"
return $?
fi
ps -ef | awk -v pattern="$pattern" '
NR == 1 {
print
next
}
index($0, pattern) {
print
matched = 1
}
END {
exit matched ? 0 : 1
}
'
} }
export -f ppg export -f ppg
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@@ -123,17 +143,42 @@ gpid()
disp E "Usage: gpid <process_name [process_name2 ...]>" disp E "Usage: gpid <process_name [process_name2 ...]>"
return 1 return 1
fi fi
[[ $UID -eq 0 ]] && local psopt="-A" local single=0
[[ $# -eq 1 ]] && local single=1 local found=0
for pid in $@; do local proc_name result
local result=$(ps $psopt | grep $pid | awk '{print $1}' | sed "s/\n/ /")
if [[ $single ]]; then [[ $# -eq 1 ]] && single=1
[[ -n "$result" ]] && echo "${result//$'\n'/ }"
for proc_name in "$@"; do
result=""
if command -v pgrep >/dev/null 2>&1; then
result=$(pgrep -d ' ' -x -- "$proc_name")
else else
[[ -n "$result" ]] && echo "$pid: ${result//$'\n'/ }" result=$(ps -eo pid=,comm= | awk -v proc="$proc_name" '
$2 == proc {
if (out != "") {
out = out " "
}
out = out $1
}
END {
print out
}
')
fi
[[ -z "$result" ]] && continue
found=1
if (( single )); then
echo "$result"
else
echo "$proc_name: $result"
fi fi
done done
[[ -n "$result" ]] || return 1
(( found )) || return 1
} }
export -f gpid export -f gpid
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@@ -200,6 +245,7 @@ kt()
done done
kill "$@" "$parent_pid" kill "$@" "$parent_pid"
} }
export -f kt
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------