Reputation: 31
Today when I tried to kill all the processes related to docker, I noticed something really funny:
➜ ~ ps aux | grep docker
Caesar 73944 0.0 0.0 2423372 220 s000 R+ 6:49PM 0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn docker
➜ ~ kill 73944
kill: kill 73944 failed: no such process
➜ ~ ps aux | grep docker
Caesar 74064 0.0 0.0 2432788 572 s000 R+ 6:50PM 0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn docker
➜ ~
I used ps aux | grep docker to find the process related to docker, although I am not sure if it is really a docker process. The funny thing is that: when I kill it using pid, I couldn't do it, as you can see from the screenshot. Also, I noticed that the pid changed at the second ps command.
I know the problem may look stupid, however, I couldn't find anything on Google because I didn't know how to describe it. Maybe you can help me with that. Thanks ; )
Thanks for the comments under this question. I noticed that the pid belongs to the grep process, and no wonder why the pids differ each time. Thank y'all for the help!
Upvotes: 1
Views: 2652
Reputation: 18703
You're seeing the grep
process, not the docker
process. Whenever you use grep
to filter the output of ps
you'll run into this issue. To avoid listing the grep
process, the canonical solution is to put square brackets around the first character in the target process name:
ps aux | grep '[d]ocker'
Since the search string contains square brackets (which don't effectively alter the regular expression) it will no longer be a match for the regular expression itself when found in the name of the grep
process.
Upvotes: 4