Link to home
Start Free TrialLog in
Avatar of rongz
rongz

asked on

get active process list in linux

Hi,
In HP-UX, you can get a list of active processes and their relevant information by calling pstat_getproc(). How can this be achieved in linux using c/c++? I.e. how can i get a list of current running processes?

It seems that one way to do it is: read the /proc and go to all /proc/xxxx/staus(xxxx are digits) and check if xxxx is in running state, if yes, count the process as active process and push it to a list. I wonder if there is other simple way and can somebody show me an example. Thanks.
Avatar of sunnycoder
sunnycoder
Flag of India image

You can launch "ps -a" command using exec() or system() or popen()
ASKER CERTIFIED SOLUTION
Avatar of sunnycoder
sunnycoder
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No linux requires You to scan /proc
And ps in fact reads /proc/[PID]/stat
Even if ps reads from proc it saves significant programming effort to call ps rather than duplicate the functionality in own program!!
Avatar of rongz
rongz

ASKER

By the way, In HP-UX, ticks of cpu time of a process can be get from
pst_status structure filled when calling pstat_getproc().
How in linux get the ticks of cpu time of a process. Thanks.

utime and stime entries in /proc/pid/stat ...