ps -ef | grep port=9| grep -v grep | awk '{print $2}' | while read pid; do
# 获取启动目录
start_dir=$(pwdx $pid 2>/dev/null | awk '{for (i=2; i<=NF; i++) printf "%s ", $i; print ""}')
# 获取端口信息(使用 ss 命令)
ports=$(ss -ltnp | grep ",pid=$pid," | awk '{print $4}' | awk -F: '{print $NF}' | tr '\n' ',' | sed 's/,$//')
# 打印信息
printf "PID: %s\tStart Dir: %s\tPorts: %s\n" "$pid" "$start_dir" "$ports"
done
ps -ef | grep port=9 | grep -v grep | awk '{print $2}' | while read pid; do# 获取启动目录start_dir=$(pwdx $pid 2>/dev/null | awk '{for (i=2; i<=NF; i++) printf "%s ", $i; print ""}')# 获取端口信息(使用 ss 命令)ports=$(ss -ltnp | grep ",pid=$pid," | awk '{print $4}' | awk -F: '{print $NF}' | tr '\n' ',' | sed 's/,$//')# 打印信息printf "PID: %s\tStart Dir: %s\tPorts: %s\n" "$pid" "$start_dir" "$ports"
done