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>"
return 1
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
# ------------------------------------------------------------------------------
@@ -123,17 +143,42 @@ gpid()
disp E "Usage: gpid <process_name [process_name2 ...]>"
return 1
fi
[[ $UID -eq 0 ]] && local psopt="-A"
[[ $# -eq 1 ]] && local single=1
for pid in $@; do
local result=$(ps $psopt | grep $pid | awk '{print $1}' | sed "s/\n/ /")
if [[ $single ]]; then
[[ -n "$result" ]] && echo "${result//$'\n'/ }"
local single=0
local found=0
local proc_name result
[[ $# -eq 1 ]] && single=1
for proc_name in "$@"; do
result=""
if command -v pgrep >/dev/null 2>&1; then
result=$(pgrep -d ' ' -x -- "$proc_name")
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
done
[[ -n "$result" ]] || return 1
(( found )) || return 1
}
export -f gpid
# ------------------------------------------------------------------------------
@@ -200,6 +245,7 @@ kt()
done
kill "$@" "$parent_pid"
}
export -f kt
# ------------------------------------------------------------------------------