Skip to content
Advertisement

Issue finding the process id from shell scipt

mySample.sh

JavaScript

The above command is printing and killing the temporary process that was created for grep Even though i do not have any process running with Abcd, This is printing pid Any ways to ignore it, iam actually ignoring it using grep -v, still…

JavaScript

Any Issue in fetching the process id.?

Basic command line output is below,After running a process with name Acc_Application_One

[root@localhost Desktop]# ps -Af | grep Acc

root 6251 2758 0 16:16 pts/1 00:00:00 ./Acc_Application_One

root 7288 2758 0 16:57 pts/1 00:00:00 grep Acc

Changed mySample.sh

JavaScript

And the output is

[root@localhost Desktop]# mySample.sh Acc_Application_One

6251 7289

Advertisement

Answer

To kill a process with the pattern anywhere in command line use pkill -f:

JavaScript

As per man pkill:

-f Match the pattern anywhere in the full argument string of the process instead of just the executable name.

Similarly you can use pgrep -f "$1" to list the process id of the matching process.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement