-   Programming (
-   -   Process Enumeration with C++ (

amitrawal_17 06-07-2004 06:05 AM

Process Enumeration with C++
hello ,everybody,

i am stuck.. i m new to Linux and know nothing abou it.....
i want to know following things with C++ program on Linux....

i would be gien list of
apache server cte... and i have to fetch the followings......

Process is runnin or not/???
Process related Info - memoru consumed..cpu uasage ..No of threads runnning..etc...

i am writting a C++ application plz give me related help...
i know three are linux command which gives hese info like PS but how to use them in C++ can i capture the out put of such commands ...or is there another way like we havein Windows platform, called WIN-API...
plzgive me C++ COde it would be a greatr help for me...
really expecfting some quick answers...i m really really really in hurry and badly stuck...


jim mcnamara 06-07-2004 12:22 PM

popen() will let you execute a command and capture the output via a redirected pipe.


FILE *fd;
char cmdoutput[496]={'\0'};
fd=popen("ps -ef", "r");
                  /* cmdoutput  has a line of output */
        } else{
                if(feof(fd)) break;
                perror("Pipe processing error");

amitrawal_17 06-08-2004 02:16 AM

sorry to bug u again but i m still facing the problem.i m very new to linux and programming . i fired the samplecode given by you and it returns the following result..


amit 18186 18185 0 11:47 pts/3 00:00:00 ps -ef

Program exited successfully with errcode (0)
Press the Enter key to close this terminal ...


even if i try changing the command it is not helping me i have fired ps -aux too but the result is the same...
i m confused.....
my inputs would be process name only and i have to find out everything about the process then...
CPU usgae
No of THreads Running
Memory Usage etc...

plz help me out.....

best regs

All times are GMT -5. The time now is 02:18 PM.