开发者

execution of a command (unexpected behaviour)

开发者 https://www.devze.com 2023-02-22 01:40 出处:网络
ps -ef | grep \"someprocess\" output lines contain : .........................someprocess .........................ps -ef | grep \"someprocess\"

ps -ef | grep "someprocess" output lines contain :

.........................someprocess
.........................ps -ef | grep "someprocess" 

开发者_运维百科Can somebody explain how this gets executed??

If I am checking for a process that is running or not it will allways come as running since ps -ef | grep "someprocess" will always be there Of course I know that I can do ps -ef | grep "someprocess" | grep -v 'grep'

But I want to know the process of execution of the above to be clear. why do I get the line that I just executed (ps -ef | grep "someprocess") searching for a process?


From this blog post:

Why does grep show itself? Because the pipe is created by the shell an instant before ps is executed so when the latter searches for all the loaded processes even grep is found.


Or use

pgrep -fl somepattern

that will not show the pgrep process by default

Similarly, pkill will not kill itself :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号