execution of a command (unexpected behaviour)
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 beforeps
is executed so when the latter searches for all the loaded processes evengrep
is found.
Or use
pgrep -fl somepattern
that will not show the pgrep process by default
Similarly, pkill will not kill itself :)
精彩评论