FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 11-22-2010, 06:12 PM
"T. Alex Chen"
 
Default Retrieve process ID from process name

I*am trying to retrieve the process ID from a process' name, optionally with*its command parameters.
I look up the man page of*'sysctl' and the use of this API seems to be discouraged. It points the /proc file system.
The /proc does contains all the running processes, with their ID as the directory name, and their command line as a file 'cmdline' under that subdirectory.
Is there an API*get the information out easily*or do I have to open the file '/proc' and iterate through the sub-directories with number (PID) as the file name and get the content of*'cmdline'. (That seems to be very cumbersome.)
*
Any help is appreciated.Alex
 
Old 11-23-2010, 06:59 AM
Alberto Luaces
 
Default Retrieve process ID from process name

"T. Alex Chen" writes:

> I am trying to retrieve the process ID from a process' name, optionally with its command parameters.
> I look up the man page of 'sysctl' and the use of this API seems to be discouraged. It points the /proc file system.
> The /proc does contains all the running processes, with their ID as the directory name, and their command line as a file 'cmdline' under that subdirectory.
> Is there an API get the information out easily or do I have to open the file '/proc' and iterate through the sub-directories with number (PID) as the file name and get the content of 'cmdline'. (That seems
> to be very cumbersome.)

Maybe the source of `pidof' (in sysvinit-utils) can give a hint.

--
Alberto


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 87pqtw8o7l.fsf@eps142.cdf.udc.es">http://lists.debian.org/87pqtw8o7l.fsf@eps142.cdf.udc.es
 
Old 11-23-2010, 03:18 PM
Mike McClain
 
Default Retrieve process ID from process name

On Tue, Nov 23, 2010 at 08:59:42AM +0100, Alberto Luaces wrote:
> "T. Alex Chen" writes:
>
> > I am trying to retrieve the process ID from a process' name, optionally with its command parameters.
> > I look up the man page of 'sysctl' and the use of this API seems to be discouraged. It points the /proc file system.
> > The /proc does contains all the running processes, with their ID as the directory name, and their command line as a file 'cmdline' under that subdirectory.
> > Is there an API get the information out easily or do I have to open the file '/proc' and iterate through the sub-directories with number (PID) as the file name and get the content of 'cmdline'. (That seems
> > to be very cumbersome.)
>
> Maybe the source of `pidof' (in sysvinit-utils) can give a hint.
> Alberto

pgrep $process_name will give you the pid
or
ps auwx | grep $process_name | grep -v grep
will give you both pid and command line
Mike
--
Satisfied user of Linux since 1997.
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 20101123161806.GA21819@playground.mcclains.net">ht tp://lists.debian.org/20101123161806.GA21819@playground.mcclains.net
 

Thread Tools




All times are GMT. The time now is 09:53 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org