4
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.

user1757703
  • 2,925
  • 6
  • 41
  • 62

2 Answers2

10

The usual trick is

ps x | grep '[v]sftpd'
choroba
  • 231,213
  • 25
  • 204
  • 289
8

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)

Brian Agnew
  • 268,207
  • 37
  • 334
  • 440