LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-21-2009, 04:33 AM   #1
sivareddy_jntu
LQ Newbie
 
Registered: Jun 2009
Posts: 6

Rep: Reputation: 0
Is There any API in linux to know process ID and it's status


Hai All,

I just need an API to know a process ID and it's status,whether it is alive or not.



Any help would be appreciated greatly.


Regards,
-Siva.
 
Old 08-21-2009, 04:52 AM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
In what language ?
 
Old 08-21-2009, 04:58 AM   #3
sivareddy_jntu
LQ Newbie
 
Registered: Jun 2009
Posts: 6

Original Poster
Rep: Reputation: 0
hai,
In 'C' Language i need an API to know about process ID and it's status.



Thanks for ur quick response.



Regards,
-Siva.
 
Old 08-21-2009, 07:42 AM   #4
w1k0
Senior Member
 
Registered: May 2008
Location: Poland
Distribution: Slackware (personalized Window Maker), Mint (customized MATE)
Posts: 1,309

Rep: Reputation: 234Reputation: 234Reputation: 234
Maybe the command ps axu will be sufficient for your needs?
 
Old 08-21-2009, 08:01 AM   #5
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
You may find it easier to get the information you want by opening and reading the "file" /proc/self/status

You can get a sample of the format and some of the available information by typing
Code:
head -n 25 /proc/self/status
That, of course, gives the information about the process running head. If your own program opens and reads that file, it will get the information about itself.

The Linux kernel creates the information in that format as you read /proc/self/status. It is not like an ordinary file with the information sitting around waiting to be read.

Last edited by johnsfine; 08-21-2009 at 08:07 AM.
 
Old 08-21-2009, 08:01 AM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
to w1k0: Probably, however "ps" is a command line (shell) API, not C.

I would suggest to travel the /proc directory in C to find out what processes are alive. Be aware though that what you'll find there doesn't represent an API, might be missing if /proc is not mounted, might change from a version to another and from a distribution to another.

To check if a process is still alive while knowing its pid, you can use the kill system call with 0 as second parameter.
 
Old 08-21-2009, 06:19 PM   #7
chadwick
Member
 
Registered: Apr 2005
Location: At the 100th Meridian where the great plains begin
Distribution: Debian Testing on T60 laptop
Posts: 105

Rep: Reputation: 17
Quote:
Originally Posted by sivareddy_jntu View Post
hai,
In 'C' Language i need an API to know about process ID and it's status.
Do you mean that, given a known process ID, you want to determine the status of the process with that ID?
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Process Status D webee Linux - General 12 07-08-2019 04:03 PM
[SOLVED] process status ak.lokesh Linux - Newbie 2 01-21-2011 02:44 PM
Is there any system function/api to get values like /proc/<pid>/status ??? kunalnandi Linux - Newbie 2 05-02-2009 01:22 AM
API to detect firewall status in Linux huntneeraj Linux - Newbie 1 04-30-2009 02:26 PM
finding out package installation status/deps through api? grayFalcon Debian 3 04-25-2009 04:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:27 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration