LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   API for current running process details like process name, process id, amount of memory used (https://www.linuxquestions.org/questions/linux-general-1/api-for-current-running-process-details-like-process-name-process-id-amount-of-memory-used-4175646535/)

anki123 01-19-2019 09:36 AM

API for current running process details like process name, process id, amount of memory used
 
Quote:

Originally Posted by sonuxp (Post 3215182)
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


I'm new to linux can you please tell me the link of the documentation of API for to write a Linux C++ code to find all the current running process details like process name, process id, amount of memory used etc

berndbausch 01-20-2019 02:06 AM

You can use the proc filesystem. Documented in the proc man page. Approximate workflow:

use getpid() to get process ID
read appropriate files under /proc/<process ID>

I even found a C++ example how to access /proc: http://blog.davidecoppola.com/2016/1...line-in-linux/. And another example getting some information from several processes.

To learn more about the proc filesystem, you may want to search for procfs.

I remember the pstat(2) system call in UNIX, but it seems to me that Linux doesn't have it.


All times are GMT -5. The time now is 11:00 PM.