getrusage() in qnx4.25

I find getrusage function in unix library, but no <sys/resource.h> found.

even that the code below compiling and works but all values printed out is zero.
What das it means?

#include <sys/time.h>
#include <stdio.h>

#define RUSAGE_SELF 0
#define RUSAGE_CHILDREN -1

typedef struct rusage {
struct timeval ru_utime; /* user time used /
struct timeval ru_stime; /
system time used /
long ru_maxrss; /
max resident set size /
long ru_ixrss; /
integral shared memory size /
long ru_idrss; /
integral unshared data " /
long ru_isrss; /
integral unshared stack " /
long ru_minflt; /
page reclaims /
long ru_majflt; /
page faults /
long ru_nswap; /
swaps /
long ru_inblock; /
block input operations /
long ru_oublock; /
block output operations /
long ru_msgsnd; /
messages sent /
long ru_msgrcv; /
messages received /
long ru_nsignals; /
signals received /
long ru_nvcsw; /
voluntary context switches /
long ru_nivcsw; /
involuntary " */
} rusage;

main(){

int who = RUSAGE_SELF;
struct rusage usage;
int ret;

ret = getrusage(who, &usage);

printf(“result %d\n”, ret);

printf(“user time used %d sec %d usec\n”, usage.ru_utime.tv_sec, usage.ru_utime.tv_usec);
printf(“system time used %d sec %d usec\n”, usage.ru_stime.tv_sec, usage.ru_utime.tv_usec);

printf(“max resident set size %d\n”, usage.ru_maxrss);
printf(“integral shared memory size %d\n”, usage.ru_ixrss);
printf(“integral unshared data %d\n”, usage.ru_idrss);
printf(“integral unshared stack %d\n”, usage.ru_isrss);
printf(“page reclaims %d\n”, usage.ru_minflt);
printf(“page faults %d\n”, usage.ru_majflt);
printf(“swaps %d\n”, usage.ru_nswap);
printf(“block input operations %d\n”, usage.ru_inblock);
printf(“block output operations %d\n”, usage.ru_oublock);
printf(“messages sent %d\n”, usage.ru_msgsnd);
printf(“messages received %d\n”, usage.ru_msgrcv);
printf(“signals received %d\n”, usage.ru_nsignals);
printf(“voluntary context switches %d\n”, usage.ru_nvcsw);
printf(“involuntary %d\n”, usage.ru_nivcsw);

That’s it is probably unsupported ;-) The unix library tries to add unix like capability but it’s not 100%.

As far as I know most of the stats returned don’t even exists in QNX4…

I insert the job before getrusage() like

unsigned long i;
for(i=0;i<0x8fffffff;i++){
cos(1.234);
}

and rusage.ru_utime shows execution time like utilite time do.

That’s enought to many cases.
I think it needs to patch qnx4 itself.
AFAIK Linux uses not all stats in rusage too.

patch qnx4?? Huh?

If you says rusage.ru_utime works, why are you saying in your first that all values are 0.

In first program there is nothihg to do, and if you insert delay(…) there is still nothing to do and utime is 0 unless you define usage to something else before getrusage() call. You may test it.

In sys/resource.h declared five functions.

int getpriority(int, id_t);
int getrlimit(int, struct rlimit *);
int getrusage(int, struct rusage *);
int setpriority(int, id_t, int);
int setrlimit(int, const struct rlimit *);

setprioriy() may be redefine to setprio() and getpriority() to getprio(), but set/getrlimit I don’t know how.

Set/get limit are not supported, you can replace them by a return -e and errno set to ENOTSUP.