moved helpers separately

This commit is contained in:
2026-10-13 16:21:24 +02:00
parent ba1e07744e
commit 9911f6d01d
33 changed files with 1489 additions and 1089 deletions
+3 -76
View File
@@ -36,6 +36,9 @@
load_conf "processes"
# Common helpers, then the ones private to this module (helpers/processes.sh)
declare -F _profile_load_helpers >/dev/null || . "$(dirname -- "${BASH_SOURCE[0]}")/../helpers/common.sh"
_profile_load_helpers "${BASH_SOURCE[0]}"
# ------------------------------------------------------------------------------
# Search processes matching the given string
@@ -106,9 +109,6 @@ ppg()
'
}
export -f ppg
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# List processes owned by a specific user
# Usage: ppu <username>
@@ -156,9 +156,6 @@ ppu()
ps -u "$1" -o "${PPU_DEFAULT_FORMAT:-pid,user,%cpu,%mem,start,time,command}"
}
export -f ppu
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# List processes by exact command name (no path/parameters)
# Usage: ppn <command_name>
@@ -217,9 +214,6 @@ ppn()
'
}
export -f ppn
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Get PID list of the given process name
# Usage: gpid <process_name [process_name2 ...]>
@@ -300,41 +294,6 @@ gpid()
(( found )) || return 1
}
export -f gpid
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Internal helper: take the kill-style signal arguments (-9, -KILL, -SIGHUP)
# out of an argument list. getopt rejects them as unknown options, so they must
# be removed before it runs. They are recognised anywhere before a "--"
# (digits, or upper-case names, which cannot clash with the lower-case options
# of the callers); everything after "--" is left untouched.
# Usage: _proc_split_signals <signals_array> <rest_array> [args...]
_proc_split_signals()
{
local -n _pss_sigs="$1" _pss_rest="$2"
shift 2
_pss_sigs=()
_pss_rest=()
local a
while [[ $# -gt 0 ]]; do
a="$1"
shift
if [[ $a == "--" ]]; then
_pss_rest+=(-- "$@")
break
fi
if [[ $a =~ ^-([0-9]+|SIG[A-Z0-9+-]+|[A-Z][A-Z0-9+-]*)$ ]]; then
_pss_sigs+=("$a")
else
_pss_rest+=("$a")
fi
done
}
export -f _proc_split_signals
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Kill all processes owned by the given users (kill user)
# Usage: ku [options] <username1 [username2 ...]>
@@ -460,36 +419,6 @@ ku()
return "$rc"
}
export -f ku
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Internal helper of kt: send a signal to a process and, first, to all its
# descendants (depth first, so a parent never outlives the children it could
# respawn from). A failure does not stop the others; the status is non-zero if
# any kill failed.
# Usage: _kt_tree <dry_run 0|1> <pid> [kill_args...]
_kt_tree()
{
local dry="$1" pid="$2" child rc=0
shift 2
for child in $(pgrep -P "$pid" 2>/dev/null); do
_kt_tree "$dry" "$child" "$@" || rc=1
done
if (( dry )); then
printf "DRY-RUN: "
printf "%q " kill "$@" "$pid"
printf "\n"
else
kill "$@" "$pid" || rc=1
fi
return "$rc"
}
export -f _kt_tree
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Kill all children of a process then the process (kill tree)
# Usage: kt [options] <pid>
@@ -580,6 +509,4 @@ kt()
export -f kt
# ------------------------------------------------------------------------------
# EOF