Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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);
}
}
}

![]() |
![]() |
![]() |

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