LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-14-2008, 08:35 PM   #1
kushkothari
Member
 
Registered: Oct 2008
Posts: 31

Rep: Reputation: 15
Question 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?
 
Old 11-14-2008, 08:44 PM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,287

Rep: Reputation: 1030Reputation: 1030Reputation: 1030Reputation: 1030Reputation: 1030Reputation: 1030Reputation: 1030Reputation: 1030
"man pidof"
 
Old 11-14-2008, 09:10 PM   #3
kushkothari
Member
 
Registered: Oct 2008
Posts: 31

Original Poster
Rep: Reputation: 15
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
 
Old 11-14-2008, 10:52 PM   #4
ArfaSmif
Member
 
Registered: Oct 2008
Location: Brisbane Australia
Distribution: always back to Fedora
Posts: 241

Rep: Reputation: 50
a=`/sbin/pidof -s programname`
kill -9 $a

also have a look at "killall"

Last edited by ArfaSmif; 11-14-2008 at 10:55 PM. Reason: added killall info
 
Old 11-14-2008, 11:53 PM   #5
abolishtheun
Member
 
Registered: Mar 2008
Posts: 183

Rep: Reputation: 31
i use pgrep... never even heard of pidof til now. anyone care to compare/contrast these two?
 
Old 11-15-2008, 12:42 AM   #6
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by abolishtheun View Post
i use pgrep... never even heard of pidof til now. anyone care to compare/contrast these two?
man pgrep
man pidof
 
Old 11-18-2008, 10:26 PM   #7
kushkothari
Member
 
Registered: Oct 2008
Posts: 31

Original Poster
Rep: Reputation: 15
Thanks a lot.
 
Old 11-19-2008, 12:20 AM   #8
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Quote:
Originally Posted by abolishtheun View Post
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
 
Old 11-19-2008, 05:06 AM   #9
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 4,100

Rep: Reputation: 494Reputation: 494Reputation: 494Reputation: 494Reputation: 494
kill $(pidof myprogram)

jlinkels
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[C++] Get process ID (PID) Moraxus Programming 5 10-16-2008 12:31 PM
how to get process status using pid? hongxing Linux - Software 2 04-11-2006 07:11 AM
Getting pid of a process!! vishamr2000 Programming 31 09-09-2005 08:46 PM
Getting PID of running process in C/C++ laikos Programming 9 03-15-2004 03:33 AM
Get Next PID of Process Tree zer0python Programming 7 11-26-2003 11:56 AM


All times are GMT -5. The time now is 12:06 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration