Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 05-09-2006, 07:38 AM   #1
LQ Newbie
Registered: Mar 2006
Posts: 7

Rep: Reputation: 0
How to read in a processes PID

Hi All,

I am trying to read in a processes PID so that I can kill it at a later stage with a script, id like to be able to store the PID as a variable in a "C" program, but i havent a clue how to read in the PID of a process.

Is it possible to get the PID of a process without doing a ps -es??

Old 05-09-2006, 08:54 AM   #2
Registered: May 2006
Distribution: Fedora Core, FreeSpire, PC-BSD, NetBSD
Posts: 96

Rep: Reputation: 15
Take a look about this API.

There has a section Process management that describe all the thing you need.
Good luck.

If you have any questions - be my guest.
Old 05-09-2006, 11:26 AM   #3
Registered: Sep 2005
Location: Old Blighty
Distribution: Slackware, NetBSD
Posts: 536

Rep: Reputation: 32
The pid of a process is a variable stored by the kernel. Thus, chances are the system call to retrieve the pid will be documented in the system call section of the man pages (section 2).

[~] find /usr/share/man/man2 | grep pid
Hmmm, getpid sounds like it might be a way to get the pid, let's see, 'man getpid'.
Old 05-09-2006, 07:48 PM   #4
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
And don't forget all the Good Stuff you can parse for in "/proc". For example:
cat /proc/1/cmdline
init [3]


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
kill pid.... won't work with 'pid' variable given.. sachitha Programming 6 03-06-2006 08:48 PM
shell script to read ps -e output and determine process double processes. dr_zayus69 Programming 1 09-21-2005 06:37 PM
/var/run/[XXX].pid - Tcl pid code liguorir Linux - Software 1 05-20-2004 11:32 PM
adsl-status can't read pppoe PID file with rp-pppoe program setup Smarvy Linux - Newbie 2 03-14-2004 12:35 AM
ERROR: Couldn't write pid to pid file lawrencegoodman Linux - Newbie 2 02-13-2004 09:05 PM > Forums > Non-*NIX Forums > Programming

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

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