Monday, April 4, 2022

[SOLVED] how to get process id of specific process?

Issue

Say there are 3 process with names abc, abcd and abcde.

I'm using the following command to find out the process id:

ps -ef | grep abc | grep -v grep

This gives the output for all the 3 processes with their corresponding pids:

user 6009      1   0   May 11 ?           0:23 ./abc
user 28047     1   0   Apr 24 ?           0:04 ./abcd
user 28548     1   0   Apr 27 ?           0:04 ./abcde

Now what I want is a grep thing that outputs the process id of just abc without returning abcd and abcde. I know using grep -v "processname" eliminates what i want but is there anything simple and specific?


Solution

ps -ef | grep -w abc | grep -v grep
               ^
               `--- match whole words only


Answered By - Eugeniu Rosca
Answer Checked By - Pedro (WPSolving Volunteer)