Add ability to use process name

This commit is contained in:
2022-04-10 09:52:35 +03:00
parent bd0452a3ea
commit a32adb2080

View File

@@ -37,6 +37,18 @@ flags()
if [[ $1 =~ ^[0-9].*$ ]]; then
PIDS+=("$1")
export PIDS
elif [[ $1 =~ ^[a-z].*$ ]]; then
procs=$(ps aux | grep $1 | grep -v grep | grep -v "$(pwdx $$ | awk '{print $NF}')")
# exclude the path of the current script PID ^
if [[ -n "$procs" ]]; then
for proc in "$procs"; do
proc_pid=$(echo "$proc" | awk '{print $2}' | grep -v "$(pwdx $$)")
if [[ -n $(ps aux | grep "$proc_pid") ]]; then
PIDS+=("$proc_pid")
export PIDS
fi
done
fi
elif [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then
help
else