LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Is There any API in linux to know process ID and it's status (https://www.linuxquestions.org/questions/linux-general-1/is-there-any-api-in-linux-to-know-process-id-and-its-status-749243/)

sivareddy_jntu 08-21-2009 04:33 AM

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.

jlliagre 08-21-2009 04:52 AM

In what language ?

sivareddy_jntu 08-21-2009 04:58 AM

hai,
In 'C' Language i need an API to know about process ID and it's status.



Thanks for ur quick response.



Regards,
-Siva.

w1k0 08-21-2009 07:42 AM

Maybe the command ps axu will be sufficient for your needs?

johnsfine 08-21-2009 08:01 AM

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.

jlliagre 08-21-2009 08:01 AM

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.

chadwick 08-21-2009 06:19 PM

Quote:

Originally Posted by sivareddy_jntu (Post 3652127)
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?


All times are GMT -5. The time now is 03:51 PM.