查找多线程应用程序的进程号

finding the process numbers of a multithread application

如何检索已发布的多线程应用程序的进程号?我的意思是,我正在寻找一个 bash 脚本,该脚本在执行命令后将进程号放入列表中。例如:

#!/bin/bash
./run_program -nt 4
# find the list of PIDs

假设 run_program 在 ps pid 列表中创建相同的执行路径。

ARRAY=($(ps -fe | grep run_program | grep -v grep | awk '{print }' ORS=' '))

您可以在示例中访问

echo ${ARRAY[2]}

我会使用 pgrep 来检查进程 ID。

如果您只查看当前进程的子 PID,您可以使用 -P 选项:

pgrep -P $$