I know that it does (often) include the grep process and I know adding
| grep -v grep or grepping on
[f]oo instead will prevent it, but my question is more about order of operations I guess.
For example, in this contrived example, I see several grep processes:
% ps -x | grep login | grep login | grep login | grep login 2475 ?? 0:00.03 /usr/libexec/loginitemregisterd 2115 ttys004 0:00.04 login -fp jasonerickson 29715 ttys004 0:00.00 grep login 29716 ttys004 0:00.00 grep login 29717 ttys004 0:00.00 grep login 29718 ttys004 0:00.00 grep login
That tells me that
ps -x must be executed last in that line, since it lists all of those subsequent grep commands. However, it is not consistent. Sometimes it will list 4 or 3 or 2 or even none of the grep processes. That would imply to me that it is not always last.
What's going on?