Skip to Main Content

Infrastructure Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

strange behaviour on reading procfs

807567Mar 23 2007 — edited Mar 29 2007
Hello,

I have a strange behaviour reading process table from procfs. Some processes have a resident size and image size of 0 (zero). So I wrote a little test program and generated a 32bit binary. It gave me the same result. After I made a 64bit binary and this brought the expected results. Do anyone of you have an idea what i'm making wrong. Below you can find an output example and the code of the program.

Every answer is appreciated
erinda
pfs.s32
pid name nlwp %cpu %mem image resident
----------------------------------------------------------
1 init 1 0.00 0.03 2368 1184
7 svc.startd 13 0.01 0.04 8696 1720
649 snmpd 1 0.00 0.08 0 0
24151 oracle 11 0.00 7.01 0 0
....
pfs.s64
pid name nlwp %cpu %mem image resident
----------------------------------------------------------
1 init 1 0.00 0.03 2368 1184
7 svc.startd 13 0.01 0.04 8696 1720
649 snmpd 1 0.00 0.08 9352 3440
24151 oracle 11 0.00 7.01 330240 286664


and here the program
int main(int ac, char * av[])
{
struct dirent * procEntry;
char prcPath[PRARGSZ];
psinfo_t prcInfo;
pid_t pid;
int rtc;

DIR * procDir = opendir("/proc");
if(procDir == NULL)
{
printf("opendir(/proc) failed\n");
return 1;
}

printf(" pid name nlwp %%cpu %%mem image resident\n");
printf("----------------------------------------------------------\n");
rewinddir(procDir);
while(procEntry = readdir(procDir))
{
if(procEntry->d_name[0] == '.' || // skip "." and ".."
procEntry->d_name[0] == '\0') // skip empty name
{
continue;
}

pid = atoi(procEntry->d_name);
if(pid == 0 || pid == 2 || pid == 3)
{
continue;
}

size_t size = sizeof(psinfo_t);
sprintf (prcPath, "/proc/%s/psinfo", procEntry->d_name);
int pprocfs = open(prcPath, O_RDONLY);
if (pprocfs < 0)
{
return 2;
}
else
{
ssize_t bytesRead = read(pprocfs, &prcInfo, size);
if (bytesRead != size)
{
return 3;
}
close (pprocfs);
}

printf(" %5d %-15s %4d %5.2f %5.2f %8lu %8lu\n",
prcInfo.pr_pid,
prcInfo.pr_fname,
prcInfo.pr_nlwp,
(float)(100.0 * prcInfo.pr_pctcpu / 0x8000),
(float)(100.0 * prcInfo.pr_pctmem / 0x8000),
(ulong_t)prcInfo.pr_size,
(ulong_t)prcInfo.pr_rssize);
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 26 2007
Added on Mar 23 2007
4 comments
155 views