Why doesn't echo appear in ps?

I find it difficult to understand what appears in the ps command. To test my understanding, I created a script below the dummy

#!/bin/bash for i in {1..100000} do date -u date -u date -u done 

while running this script, I opened a new terminal and re-executed

 ps -eaf | grep date | grep -v grep 

and I was able to process the output date.

I later changed the script mannequin, replacing date -u with echo "what is going on"

  #!/bin/bash for i in {1..100000} do echo "What is going on" echo "What is going on" echo "What is going on" done 

when running the updated layout script, I opened a new terminal and re-executed

 ps -eaf | grep echo | grep -v grep 

and the echo never showed up. Why is this? I suspect the reason is that the script is a bash script, maybe it uses the built-in echo, so it did not appear in the ps output. I'm right? What am I missing here?

+1
source share
1 answer

echo is built into bash:

 $ type echo echo is a shell builtin 

This means that a new process is not created when echo starts. All work is done using the bash process, which is a more efficient way.

You can explicitly run a non-built echo :

 command echo "What is going on" 

These forks and execs /bin/echo instead allow it to be displayed in ps .

+7
source

All Articles