Operating System - HP-UX
1754016 Members
7356 Online
108811 Solutions
New Discussion юеВ

Re: aCC pstat compile error.

 
SOLVED
Go to solution
James Brand
Frequent Advisor

aCC pstat compile error.

I'm trying to compile example code from the pstat(2) man page -

/*
* Example 4: Get a particular process' information
*/
{
struct pst_status pst;
int target = (int)getppid();

if (pstat_getproc(&pst, sizeof(pst), (size_t)0, target) != -1)
(void)printf("Parent started at %s", ctime(&pst.pst_start));
else
perror("pstat_getproc");
}

It fails compaining about the argument to ctime()

Error 212: "stat.c", line 31 # Argument type 'int *' does not match expected parameter type 'const long *'.
(void)printf("Parent started at %s", ctime(&pst.pst_start));


It does compile with harsh warnings, and runs, using cc or gcc. Any ideas on how to fix this code?
Thanks,
Jim
2 REPLIES 2
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: aCC pstat compile error.

It's missing a few header files and a cast to (time_t *). This should fix you.

This is not uncommon for man pages; some have not been updated for years.

#include
#include
#include
#include
#include
#include

int doit(void)
{
struct pst_status pst;
int target = (int)getppid();

if (pstat_getproc(&pst, sizeof(pst), (size_t) 0, target) != -1)
(void)printf("Parent started at %s", ctime((time_t *) &(pst.pst_start)));
else perror("pstat_getproc");
return(0);
}

int main(void)
{
int d;

d = doit();
return(d);
}
If it ain't broke, I can fix that.
James Brand
Frequent Advisor

Re: aCC pstat compile error.

A. Clay,

I had the header files but was missing the type cast to (time_t *). This fixed it, thanks very much.

Jim