Computing.Net > Forums > Unix > Get memory and Cpu using proc

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Get memory and Cpu using proc

Reply to Message Icon

Name: Bala
Date: October 3, 2000 at 16:06:13 Pacific
Comment:

I am not sure how to use proc to receive CPU and memory.

My specific question, how should I use ioctl to read memory and cpu. When I use ioctl with PIOCPSINFO, PIOCSTATUS, PIOCGROUPS I am not able to get any answers. What am I missing? Any help is greatly appreciated.

My program follows:

pid_t getpidbyname(char *name,pid_t skipit)
{
DIR *dp;
struct dirent *dirp;
prpsinfo_t retval;
prstatus_t val;
prcred_t user;
int fd;
pid_t ourretval=-1;
int i = 0;

if((dp=opendir("/proc"))==NULL){
return -1;
}
chdir("/proc");
while((dirp=readdir(dp))!=NULL)
{
i++;

if(dirp->d_name[0]!='.')
{
if((fd=open(dirp->d_name,O_RDONLY))!=-1)
{
printf("Dummy name: %s\n",dirp->d_name);
if( (ioctl(fd,PIOCPSINFO,&retval)!=-1) &&
(ioctl(fd,PIOCSTATUS,&val)!=-1) &&
(ioctl(fd,PIOCGROUPS,&user)!=-1) )
{

printf("Numeric Process State: %c\n", retval.pr_state);
printf("Printable char rep: %c\n", retval.pr_sname);
printf("Process terminated but not valid for: %c\n", retval.pr_zomb);
printf("Nice for CPU usage: %c\n", retval.pr_nice);
printf("Process flags: %d\n", retval.pr_flag);
printf("Real User ID: %d\n", retval.pr_uid);
printf("Real Group ID: %d\n", retval.pr_gid);
printf("Process ID: %d\n", retval.pr_pid);
printf("Parent Process ID: %d\n", retval.pr_ppid);
printf("CPU Usage: %c\n", retval.pr_cpu);
printf("Last content of Exe'd pathname: %s\n", retval.pr_fname);
printf("Initial char of Arg list: %s\n\n", retval.pr_psargs);

printf("Scheduling Class name: %s\n", val.pr_clname);

printf("

if(!strcmp(retval.pr_fname,name))
{
ourretval=(pid_t)atoi(dirp->d_name);
if(skipit!=-1 && ourretval==skipit)
{
ourretval=-1;
}
else{
close(fd);
break;
}
}
}
close(fd);
}
}
}



Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Get memory and Cpu using proc

Getting processes with more CPU use www.computing.net/answers/unix/getting-processes-with-more-cpu-use/7750.html

How to get memory information www.computing.net/answers/unix/how-to-get-memory-information-/4177.html

Process monitoring www.computing.net/answers/unix/process-monitoring/7370.html