简体   繁体   中英

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.

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM