![]() |
cpu usage of a single process
this is the c code to get the pids and %cpu n %mem in linux/unix
Code:
FILE *fp;if i give input as pid of a process, how can i get the %cpu and mem of that process only? :confused: can someone gimme the code to it? :rolleyes: thanks in advance :) |
Re: cpu usage of a single process
Code:
ps -eo pid,pcpu,pmem | awk '{if ($1==<pid_here>) print "PID\tCPU\tMEM\n" $1 "\t" $2 "\t" $3}' |
Re: cpu usage of a single process
hii i got that in shell scripting...
how do i do that in c code?? the c code which i have given has to work in linux. i want to modify the code so that when given input by user->pid of a process, it shud give the %cpu and %mem... like: printf("enter the pid:); scanf("%d",pid); ....then i'm stuck here... |
Re: cpu usage of a single process
[QUOTE=sandyk]
printf("enter the pid:"); QUOTE] typo |
Re: cpu usage of a single process
Code: C
|
Re: cpu usage of a single process
i'm getting the following errors for the line with sprintf
over.c:11: warning: passing arg 2 of `sprintf' makes pointer from integer without a cast over.c:11: error: invalid initializer can yu please tell me why is that? |
Re: cpu usage of a single process
Sorry for the blunder,
Code: C
|
Re: cpu usage of a single process
ohh i got that..
but sprintf is not working as in that is the thing which is showing errors. |
Re: cpu usage of a single process
Code:
#include<stdio.h>input=pid of a process output=its corresponding %cpu and %mem but this is not working...someone please help me compile it. |
Re: cpu usage of a single process
Code: C
|
| All times are GMT +5.5. The time now is 09:06. |