I am using bash. I have a file named "a2draw" that contains only 1 line:
sleep 99999
I start it using this command:
bash a2draw &
Now, I know and understand the trick with square bracket that allows you to omit grep process in ps output:
ps aux | grep cron
root 1079 0.0 0.0 2596 788 ? Ss Mar25 0:00 cron
root 1119 0.0 0.0 3684 696 ? Ss Mar25 0:00 /usr/sbin/incrond -f /etc/incron.conf
ja 29781 0.0 0.0 4368 820 pts/10 S+ 12:49 0:00 grep cron
ps aux | grep [c]ron
root 1079 0.0 0.0 2596 788 ? Ss Mar25 0:00 cron
root 1119 0.0 0.0 3684 696 ? Ss Mar25 0:00 /usr/sbin/incrond -f /etc/incron.conf
But it somehow doesn't work in the subshell that has jobs running in the background:
jobs
[1]+ Running bash a2draw &
ps aux | grep [a]2draw
ja 22977 0.0 0.0 5172 1080 pts/10 S 12:21 0:00 bash a2draw
ja 30242 0.0 0.0 4364 816 pts/10 R+ 12:50 0:00 grep
What is even more strange, dropping one letter from the process name yields correct results:
ps aux | grep [a]2dra
ja 22977 0.0 0.0 5172 1080 pts/10 S 12:21 0:00 bash a2draw
On another shell everything works as I expected:
ps aux | grep [a]2draw
ja 22977 0.0 0.0 5172 1080 pts/10 S 12:21 0:00 bash a2draw
ps aux | grep [a]2dra
ja 22977 0.0 0.0 5172 1080 pts/10 S 12:21 0:00 bash a2draw
I don't know what's going on. Is there something special about background jobs that modify how creation of pipe works?
ps aux | grep --color=always "[a|e|i|o|u]"
and see what happens. – goldilocks Mar 27 '13 at 13:04while [ 1 ] ; do ps aux | grep a2draw | wc -l ; done
: it should sometimes show 1, sometimes 2 (depending on the output of ps, depending on the order the shell started both sides of its pipe) – Olivier Dulac Mar 27 '13 at 13:17