Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ps aux | grep returns pid for itself too

Tags:

bash

pid

ps

I am using this command to get the process ID of another command:

ps aux | grep 7000.conf | awk '{print $2}'

This will return two PIDs:

7731
22125

I only want the first one. The second is the PID for grep in the above command. Thanks in advance to any one who knows how to alter the above command to return just the first pid.

p.s. open to a new command that does the same thing

like image 920
BryanK Avatar asked Sep 29 '13 01:09

BryanK


2 Answers

In this particular case, escaping the . to what I assume it was meant to do should work:

ps aux | grep '7000\.conf' | awk '{print $2}'

Alternatively, exclude grep:

ps aux | grep 7000.conf | grep -v grep | awk '{print $2}'
like image 123
Ry- Avatar answered Oct 06 '22 08:10

Ry-


ps aux | grep "[7]000.conf" will work as well.

like image 20
user2599522 Avatar answered Oct 06 '22 08:10

user2599522