LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   pid of a process (http://www.linuxquestions.org/questions/programming-9/pid-of-a-process-683487/)

kushkothari 11-14-2008 08:35 PM

pid of a process
 
How can I get only the PID of a process

like
ps -aef | grep "xyz"

It gives me pid but few other things also

I need only pid of process "xyz"

how can I do this?

syg00 11-14-2008 08:44 PM

"man pidof"

kushkothari 11-14-2008 09:10 PM

pidof -s programname

it gives me the pid

I have to kill a process using shell script how can i do that

I tried the following
$a=pidof -s programname
kill -9 $a

but it's not working. Can anyone help me

ArfaSmif 11-14-2008 10:52 PM

a=`/sbin/pidof -s programname`
kill -9 $a

also have a look at "killall"

abolishtheun 11-14-2008 11:53 PM

i use pgrep... never even heard of pidof til now. anyone care to compare/contrast these two?

Sergei Steshenko 11-15-2008 12:42 AM

Quote:

Originally Posted by abolishtheun (Post 3342433)
i use pgrep... never even heard of pidof til now. anyone care to compare/contrast these two?

man pgrep
man pidof

kushkothari 11-18-2008 10:26 PM

Thanks a lot.

ta0kira 11-19-2008 12:20 AM

Quote:

Originally Posted by abolishtheun (Post 3342433)
i use pgrep... never even heard of pidof til now. anyone care to compare/contrast these two?

As far as I know, pgrep/pkill come with kill, and should therefore be preferred for something like this. You need to watch out with pkill, though, because it will match a partial name, e.g. use pkill '^program$' instead of pkill program to prevent from killing myprogram, also.
ta0kira

jlinkels 11-19-2008 05:06 AM

kill $(pidof myprogram)

jlinkels


All times are GMT -5. The time now is 05:31 AM.