LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-07-2004, 05:05 AM   #1
amitrawal_17
LQ Newbie
 
Registered: Jun 2004
Posts: 2

Rep: Reputation: 0
Unhappy 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 processes...like
textpad
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 ..so plz give me related help...
i know three are linux command which gives hese info like PS but how to use them in C++ code...how 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...

regs
Ammit
 
Old 06-07-2004, 11:22 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

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

Code:
FILE *fd;
char cmdoutput[496]={'\0'};
fd=popen("ps -ef", "r");
while(1){
         if(fgets(cmdoutput,4095,fd)!=NULL){
                  /* cmdoutput  has a line of output */
         } else{
                if(feof(fd)) break;
                perror("Pipe processing error");
                exit(EXIT_FAILURE);
         }
 }
 pclose(fd);
 
Old 06-08-2004, 01:16 AM   #3
amitrawal_17
LQ Newbie
 
Registered: Jun 2004
Posts: 2

Original Poster
Rep: Reputation: 0
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..


OUTPUT
***********************************************************
EXECUTING:
/home/amit/Projects/Try/src/try
----------------------------------------------


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...
like
CPU usgae
No of THreads Running
Memory Usage etc...

plz help me out.....

best regs
Ammit
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how a father process know which child process send the signal SIGCHLD icoming Programming 10 07-20-2010 07:26 AM
Linux boot up process Vs. Windows boot up process darkskull Linux - Software 7 12-30-2006 04:21 PM
how can i get the process id on exec a process antony_csf Linux - Software 1 06-17-2004 03:06 AM
Bash Scripting - child process affecting parent process mthaddon Linux - General 1 05-02-2004 01:19 PM
problem with binding process and than execute another process chapa Programming 0 08-27-2003 03:47 AM


All times are GMT -5. The time now is 10:26 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration