My script accepts a process name as an input and kills it, I tried using pgrep but its returning two PIDs , one for the process which is running and one for the script which accepts the process name as input so am stuck! I tried using the pgrep -fo option too but that did not help either. Any suggestions would be helpful
this is my script
#!/bin/bash
ProcessName=$1
pID= pgrep -fl $ProcessName
echo $pID
so when i invoke the script its returning two PIDs
bash-3.00$ ./dynamic_values.sh test-Process
10534 /xxx/xxo/xxx/xxe --run --propFile /application/test/test-Process_Archive.tra --innerProcess
23401 /bin/bash ./dynamic_values.sh test-Process
I was expecting just 10534 but it picked up the script too . Version of OS just incase
bash-3.00$ uname -a
Linux xxxxxx 2.6.9-67.0.1.

pkill. It uses the same process findng logic aspgrepso you already know how to use it to find your process, but rather than returning the PID's to you, it just goes ahead and sends them a kill signal for you. In the mean time, it also takes care of details such as not killing itself. – Caleb Aug 29 '12 at 10:20pkillwhen using-f(which he is doing) will have the same problem. – bahamat Aug 29 '12 at 15:30-xin combination with-fto make sure you are matching the whole thing? I'm surprisedpkilldoesn't have a built in way to handle this. – Caleb Aug 29 '12 at 16:24pkillkill itself before killing the processes I wanted to kill, so I'd always assumed the implementation was good. – jw013 Aug 29 '12 at 18:40