gunjit
gunjit

Reputation: 61

how to read a list of current running process in linux using C++

i need to read the list of current running process into a C++ program. I know that one way to do is to use ps command and other is to read /proc file system but i want to know how one can get names of processes by reading /proc file system. also is there any other way to read the list.

Upvotes: 0

Views: 2068

Answers (3)

just somebody
just somebody

Reputation: 19247

you might want to try out libstatgrab, it should be able to give you unified access to that information on many different operating systems. It will still open /proc on GNU/Linux, but you won't know.

Upvotes: 2

AndiDog
AndiDog

Reputation: 70108

You can read all information from /proc/<process pid>/. I guess the file cmdline and the link exe in each of these directories will be relevant for you.

Upvotes: 0

Andrew McGregor
Andrew McGregor

Reputation: 34602

There is no other way to read the list, /proc exists for this purpose. The simplest way to find out exactly how to do this job would be to read the source for procps, which may include a library to do most of the work for you.

Upvotes: 2

Related Questions