【发布时间】:2019-09-19 01:11:06
【问题描述】:
我需要编写一个脚本来显示进程的所有曾孙的 PID,这些进程的 PID 作为参数给出。
以下脚本显示进程的孙子进程,其 PID 作为参数给出,但我需要曾孙子进程。
#!/bin/env bash
display_cpid() {
local depth=$1 pid=$2 child_pid
(( ++depth ))
while IFS= read -r child_pid; do
if (( depth < 2 )); then
display_cpid "$depth" "$child_pid"
else
echo "$child_pid"
fi
done < <(pgrep -P "$pid" | xargs)
}
display_cpid 0 "$1"
我希望脚本显示曾孙,但它显示孙。
【问题讨论】:
-
有什么问题?
-
我不知道如何让这个脚本显示曾孙。
标签: linux bash shell scripting pid