root@test:~# ps x | grep 'vsftpd'
568 ? Ss 0:00 /usr/sbin/vsftpd
28694 pts/0 S+ 0:00 grep --color=auto vsftpd
How can I exclude the self grep process itself? Also, how do I fetch the process Id (pid) given a part of the name of the process?
I am looking for something along the lines that it will give me pid given the name and excludes the self grep process.
The usual trick is
ps x | grep '[v]sftpd'
The traditional way would be:
ps x | grep 'vsftpd'| grep -v grep
in which grep -v expr
returns everything not matching expr
You can then use awk
to extract the relevant field (the pid in your case)
ps x | grep 'vsftpd'| grep -v grep | awk '{ print $2 }'
(the $2
corresponds to the relevant field/column)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With