Operating System - Linux
1752725 Members
5593 Online
108789 Solutions
New Discussion юеВ

Problem with pstat_getproc

 
SOLVED
Go to solution
Andreas Tsamis
Advisor

Problem with pstat_getproc

Im using the following code (found in man pages) to get processes info, and i get an error saying

pstat_getproc failed: Value too large to be stored in data type

Source Code:
#define BURST ((size_t)10)

struct pst_status pst[BURST];
int i, count;
int idx = 0; /* index within the context */

while ((count=pstat_getproc(pst, sizeof(pst[0]),BURST,idx))>0) {
for (i = 0; i < count; i++) {
(void)printf("pid is %d, command is %s\n",pst[i].pst_pid, pst[i].pst_ucomm);
}
idx = pst[count-1].pst_idx + 1;
}

if (count == -1)
perror("pstat_getproc()");
#undef BURST
8 REPLIES 8
Ermin Borovac
Honored Contributor

Re: Problem with pstat_getproc

Try compiling your program with -D_PSTAT64. The following text is from pstat(2).

Notes
A wide (64 bit) version of the pstat interfaces are available for
narrow (32 bit) applications to use. A narrow application could use
the flag -D_PSTAT64 at compile time to switch to the wide interfaces.
Using this compiler flag in a narrow application is equivalent to
using the default interfaces on a wide system.
Laurent Menase
Honored Contributor

Re: Problem with pstat_getproc

#include
#include

#define BURST ((size_t)10)

main(){
struct pst_status pst[BURST];
int i, count;
int idx = 0; /* index within the context */

while ((count=pstat_getproc(pst, sizeof(pst[0]),BURST,idx))>0) {
for (i = 0; i < count; i++) {
(void)printf("pid is %d, command is %s\n",pst[i].pst_pid, pst[i].pst_ucomm);
}
idx = pst[count-1].pst_idx + 1;
}

if (count == -1)
perror("pstat_getproc()");
}
#undef BURST

I see no problem on my system. What is your system? do you have the error on compile or on exec?
How many process do you have?
Andreas Tsamis
Advisor

Re: Problem with pstat_getproc

Flag -D_PSTAT64 doesn't work;
I'm working on an Itanium HPUX 11 v 2

I get the error when i execute the program.

This is the complete o/p:
I added some lines to o/p the pst size and no of processes.

bash-3.00# ./sysinf
Size of pst 776
pstat_getproc failed: Value too large to be stored in data type

*** 24 processes, 0 threads running
Andreas Tsamis
Advisor

Re: Problem with pstat_getproc

Basically i'm trying to make a "light" version of "top" so i can send selectively data about resources and processes using tcpip to win and other unix machines.
Ermin Borovac
Honored Contributor
Solution

Re: Problem with pstat_getproc

I've just tried program that Laurent posted on 11iv2 itanium box and it worked fine when compiled with -D_PSTAT64 flag. If I don't use this flag error "Value too large" occurs.

$ cc -V
cc: HP aC++/ANSI C B3910B A.06.02 [Mar 24 2005]
$ cc -D_PSTAT64 pstat.c
$ ./a.out
pid is 0, command is swapper
pid is 1, command is init
pid is 8, command is ioconfigd
pid is 9, command is nfsktcpd
pid is 10, command is autofskd
pid is 11, command is lvmkd
pid is 12, command is lvmkd
pid is 13, command is lvmkd
pid is 14, command is lvmkd
pid is 15, command is lvmkd
pid is 16, command is lvmkd
...

If this still doesn't work for you try compiling 64-bit binary with +DD64 option to cc.
Andreas Tsamis
Advisor

Re: Problem with pstat_getproc

Thanks is now working
vinod_25
Valued Contributor

Re: Problem with pstat_getproc

hi andreas,

This error "pstat_getproc failed: Value too large to be stored in data type" oocours when a 32 bit application running on a 64 bit booted machine...

Check If the machine is booted in 64-bit mode, getconf KERNEL_BITS
and it should return "64".

32-bit applications that will be deployed on 64-bit HP-UX must use the
pstat() wrappers turned on with -D_PSTAT64 in order to function correctly
and remain compatible on 64-bit HP-UX

Good Luck

Vinod K
Leo Lai
Occasional Contributor

Re: Problem with pstat_getproc

I just want to let you know that I had the exact same problem. I was trying to run the tool which you can find at http://h21007.www2.hp.com/dspp/tech/tech_TechSingleTipDetailPage_IDX/1,2366,5944,00.html

After reading this thread, I tried the two solutions. The -D_PSTAT64 flag didn't work for me; all the process info for all the processes would report the same number. Like the pid would be the same for all the processes.

But the +DD64 flag made it work perfectly. Thanks for your help.