Question

I'm getting this error when trying to compile this simple program. The psinfo struct is in procfs.h. It's erroring on the definition line. Why would it not know the size of psinfo?

#include <sys/procfs.h>

int main(int argc, char *argv[]) {
        struct psinfo p;
}


$ /usr/sfw/bin/gcc little.c 
little.c: In function `main':
little.c:4: error: storage size of 'p' isn't known
Was it helpful?

Solution 2

Including sys/procfs.h was done by older code using the ioctl-based proc interface. Not to break these programs, the psinfo structure is currently kept undefined by default.

As you want to use the new interface, the simpler way to overcome this issue is to use this include statement:

#include <procfs.h>

which is documented in /usr/include/sys/procfs.h:

/*
 * This definition is temporary.  Structured proc is the preferred API,
 * and the older ioctl-based interface will be removed in a future version
 * of Solaris.  Until then, by default, including <sys/procfs.h> will
 * provide the older ioctl-based /proc definitions.  To get the structured
 * /proc definitions, either include <procfs.h> or define _STRUCTURED_PROC
 * to be 1 before including <sys/procfs.h>.
 */

Of course, predefining _STRUCTURED_PROC to 1 like documented too will also work as you experienced.

OTHER TIPS

Adding "#define _STRUCTURED_PROC 1" to the header fixed the problem. It needs to be defined before including sys/procfs.h.

The problem is that procfs.h sources sys/old_procfs.h unless _STRUCTURED_PROC does not equal 0 (apparently the default).

#if !defined(_KERNEL) && _STRUCTURED_PROC == 0
#include <sys/old_procfs.h>
#else   /* !defined(_KERNEL) && _STRUCTURED_PROC == 0 */
.....
#endif

You've allocated p on the stack. You should not be freeing it. Only free() that which you malloc()ed (or calloc()ed, or etc.).

That indicates that the compiler needs to know what a struct psinfo is.

You need to include the header where the structure is defined. I don't have Solaris but, for example, this guy http://ivbel.blogspot.ca/2011/12/how-to-get-process-full-name.html also includes procfs.h before.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top