Please see the output of below ps command:
abc@smaug:~/Desktop$ ps ax | grep firefox
2213 ? Sl 2:01 /usr/lib/firefox/firefox
2644 pts/0 S+ 0:00 grep --color=auto firefox
Please explain both rows and what process id can be used to kill firefox process?
Process id 2644 keeps on changing everytime I run that command.
Best Answer
when trying to find the PID of
firefox
, you launch a new process the filters the all the unwanted processes. this filter process (grep firefox
) also contains the search-term "firefox" and thus finds itself.whenever you restart
ps ax | grep firefox
you launch a newgrep
-process, hence it's PID keeps changing.So, the short answer is:
If you want to get rid of the false positive, you can use another
grep
to filter it out:yet another option is to use
pgrep
(which will only give you the PID of the found processes)