linux - grep for process id 以获得正确的值

标签 linux

我正在使用 grep 命令获取特定的进程 ID,但有时我会得到两个进程 ID 而我的输出不正确。

 ps -ef |grep AS_Cluster.js
root      2711  2624  0 07:15 pts/0    00:00:00 grep AS_Cluster.js
root     14630 14625  0 Sep13 ?        00:32:36 node xx/x/xx/x/xx/AS_Cluster.js   

我只想获取节点xx/xxx/xx/AS_Cluster.js这个进程id的pid值。任何帮助 对此

最佳答案

优先使用pgrep(1) (可能是 pgrep -f AS_cluster.js)或将 ps 的输出通过管道传递给某些 awk 命令(参见 gawk(1) )或脚本。

关于linux - grep for process id 以获得正确的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46483817/

相关文章:

php - 使用 PHP Form Builder 类提交表单后如何保留 url 变量

linux - 为什么 CAP_NET_RAW 不能与 SO_BINDTODEVICE 一起使用?

linux - bash 替换 : separated file 中的单词

linux - 使用 ":"的 awk 字段分隔符并忽略 ":"内的空格

linux - GitLab-Runner "listen_address not defined"错误

python - 使用pip download命令时如何设置平台

c++ - 我如何故意触发 fgets() 中的错误?

linux - 未检测到支持 CUDA 的设备(使用 ubuntu 12.04.4 服务器)

linux - 如何在变量中使用路径?

linux - 使用 Linux 监控 ppp0 流量使用情况