Link to home
Start Free TrialLog in
Avatar of omdon
omdon

asked on

extracting information about the processes running from the /proc directory

I am writing a program to display the current processes running on the linux OS. I do'nt know how to access the current process information like the stat file, statm file cmdline file of the process currently running. Is there any system calls present to get these information?
Avatar of omdon
omdon

ASKER

if possible give the information on tracking a process on the /proc directory...
ASKER CERTIFIED SOLUTION
Avatar of keramati_h
keramati_h

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
#include <sys/time.h>
#include <sys/resource.h>
#include <unistd.h>

int main()
{
struct rusage data;
getrusage( RUSAGE_SELF,&data);
/* now print the wanted fields */
};
this system call gives you a struct rusage, where you find most of the stat data.

            struct rusage
            {
                 struct timeval ru_utime; /* user time used */
                 struct timeval ru_stime; /* system time used */
                 long ru_maxrss;          /* maximum resident set size */
                 long ru_ixrss;      /* integral shared memory size */
                 long ru_idrss;      /* integral unshared data size */
                 long ru_isrss;      /* integral unshared stack size */
                 long ru_minflt;          /* page reclaims */
                 long ru_majflt;          /* page faults */
                 long ru_nswap;      /* swaps */
                 long ru_inblock;         /* block input operations */
                 long ru_oublock;         /* block output operations */
                 long ru_msgsnd;          /* messages sent */
                 long ru_msgrcv;          /* messages received */
                 long ru_nsignals;        /* signals received */
                 long ru_nvcsw;      /* voluntary context switches */
                 long ru_nivcsw;          /* involuntary context switches */
            };
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: keramati_h {http:#8233396}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer