ps aux | grep returns pid for itself too

前端 未结 2 865
面向向阳花
面向向阳花 2021-01-11 12:25

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:

相关标签:
2条回答
  • 2021-01-11 13:06

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

    0 讨论(0)
  • 2021-01-11 13:09

    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}'
    
    0 讨论(0)
提交回复
热议问题