LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-25-2007, 08:50 AM   #1
kits123
LQ Newbie
 
Registered: Jul 2007
Posts: 3

Rep: Reputation: 0
Unhappy getting the cpu usage of a single process


this is the code to get the pids and %cpu n %mem


Code:
FILE *fp;
char pid[MAX]="ps -eo pid,pcpu,pmem";
fp=popen(pid,"r");
while (fgets(pid, MAX, fp)!=NULL)
printf("%s",pid);
pclose(fp);

if i give input -> pid of a process, how can i get the %cpu and mem of that process only?

can someone gimme the code to it?

thanks in advance

 
Old 07-25-2007, 09:03 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,417

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
ps -eo pid,pcpu,pmem|grep <wanted_pid>
 
Old 07-25-2007, 11:50 PM   #3
kits123
LQ Newbie
 
Registered: Jul 2007
Posts: 3

Original Poster
Rep: Reputation: 0
Unhappy

Quote:
Originally Posted by chrism01
ps -eo pid,pcpu,pmem|grep <wanted_pid>

hii that thing works when given at command prompt right?

but it wont work like this:--

Code:
scanf("%d", pid);
 char path[MAX]= "ps -eo pid,pcpu,pmem | grep $pid";
i know that wrong...
could yu correct it please?
i want the user to give a pid as in input and the give him the %cpu and %mem as output...
could yu please gimme the code...
 
  


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 to get %CPU usage of a process devershetty Linux - Newbie 1 08-18-2008 02:52 AM
How to get %CPU usage of a process devershetty Linux - Newbie 13 08-16-2008 12:51 PM
process cpu usage hamedrafi Programming 5 06-11-2007 07:32 PM
How to get %CPU usage of a process romydmisc Linux - Newbie 2 05-24-2006 02:02 PM
CPU usage of a process asharma Solaris / OpenSolaris 7 03-29-2003 03:17 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:47 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration