bash ps辅助| grep 也为自己返回 pid

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19073577/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 08:05:50  来源:igfitidea点击:

ps aux | grep returns pid for itself too

bashpidps

提问by BryanK

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

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

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

This will return two PIDs:

这将返回两个 PID:

7731
22125

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

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

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

ps 打开一个执行相同操作的新命令

回答by Ry-

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

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

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

Alternatively, exclude grep:

或者,排除grep

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

回答by user2599522

ps aux | grep "[7]000.conf"will work as well.

ps aux | grep "[7]000.conf"也会起作用。