Q: How to grep a line of ps afux filtering by PID I just want to know how to grep a line which consists of for example 
pid with number 2.
I want to grep the whole line. Also, it is very important to filter only and exactly "2". Because at the moment It filters all the number which have 2 in it. 

A: If you want to get the listing for just one particular PID, the -p option is the best way.
ps -f -p 2

for example
If you want grep to match a string only if it is the whole word, not part of another word, look at the -w flag, which matches words like
$ echo '52' | grep 2
52
$ echo '52' | grep -w 2
$

if you want to match against only a particular field, awk might be a better answer than grep.  For example, if we want to check if the second column is exactly 2 we could do
ps -af | awk '$2 == 2 {print}'


A: You could go for something like this. If you need the details of a process and you know the pid go for this.
ps afux | awk '{if($2==<pid>) print}'

