ps aux | grep也为自己返回pid [英] ps aux | grep returns pid for itself too

查看:423
本文介绍了ps aux | grep也为自己返回pid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此命令来获取另一个命令的进程ID:

I am using this command to get the process ID of another command:

ps aux | grep 7000.conf | awk '{print $2}'

这将返回两个PID:

7731
22125

我只想要第一个.第二个是上述命令中grep的PID.在此先感谢任何知道如何更改上述命令以仅返回第一个pid的人.

I only want the first one. The second is the PID for grep in the above command. Thanks in advance to any one who knows how to alter the above command to return just the first pid.

p.s.打开一个执行相同操作的新命令

p.s. open to a new command that does the same thing

推荐答案

在这种特殊情况下,将.转义为我认为应该做的应该有效:

In this particular case, escaping the . to what I assume it was meant to do should work:

ps aux | grep '7000\.conf' | awk '{print $2}'

或者,排除grep:

ps aux | grep 7000.conf | grep -v grep | awk '{print $2}'

这篇关于ps aux | grep也为自己返回pid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆