LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   How do I find the process details from the C code (https://www.linuxquestions.org/questions/linux-general-1/how-do-i-find-the-process-details-from-the-c-code-655864/)

Manjunath1847 07-15-2008 06:53 AM

How do I find the process details from the C code
 
I need to write a Linux C++ code to find all the current running process details like process name, process id, amount of memory used etc. Something like ps -ef or top output. Is there any API to get these details. Please help.

Thanks in advance.

ErV 07-15-2008 08:46 AM

Quote:

Originally Posted by Manjunath1847 (Post 3215020)
I need to write a Linux C++ code to find all the current running process details like process name, process id, amount of memory used etc. Something like ps -ef or top output. Is there any API to get these details. Please help.

Thanks in advance.

Current process information is available in /proc/self directory. Open it and see what you can get there.

sonuxp 07-15-2008 09:06 AM

Quote:

Originally Posted by ErV (Post 3215160)
Current process information is available in /proc/self directory. Open it and see what you can get there.

Ya unix API's exist for them. Even ps at the backend uses them.
U can refer to the book "Advanced Programming in unix environment" from Richard Stevens

Manjunath1847 07-18-2008 06:45 AM

From strace on ps and top, I found that these commads are finding the all process related details from /proc directory, which contain one director for each of the running process with process id as the directoy name. Inside each of this directory we can get all the details like process name, memory used, status etc...


All times are GMT -5. The time now is 09:30 AM.