Open System Services Programmer's Guide

To obtain a timestamp time with an accuracy to the microsecond in an OSS program, you must
use the Guardian JULIANTIMESTAMP procedure.
Querying Process Times
You can obtain the execution time of processes from the OSS API with the times() or clock()
function. The times() function provides more information than the clock() function.
An OSS process calls the times() or clock() function in the same way a UNIX process would.
If your program is running as a Guardian process, you can also obtain the execution time of that
Guardian process with the times() or clock() function. When a Guardian process calls the
times() or clock() function, it cannot obtain the execution time of its OSS child processes.
The processor time of a Guardian process is accumulated as user time.
Limiting Processor Time Use
You can use the Guardian SETLOOPTIMER procedure to limit the processor time consumed by an
OSS program (as opposed to the elapsed time that you would limit with the alarm() function).
Example 41 demonstrates the use of SETLOOPTIMER to control the processor time used by a
compute-bound program. The time limit can be set to a hundredth of a second.
Example 41 Using SETLOOPTIMER in an OSS Program
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <cextdecs.h(SETLOOPTIMER)>
int timelimit = 247; /* time-out for processor processing
set to 2.47 seconds */
/* Catch time-out signal. */
void catchtimeout(arg) {
printf("Program used more than %d hundredths of a seconds\n",\
timelimit);
exit(1);
}
struct sigaction action;
int main(int argc, char *argv[]) {
int i;
/* Set up processor processing time-out signal-catching routine. */
action.sa_handler = catchtimeout;
sigaction(SIGTIMEOUT, &action, NULL);
/* Set processor processing time-out to specified limit. */
SETLOOPTIMER((short)timelimit);
for(i=0;i < 100000000; i++) i=i; /* compute loop */
return(0);
}
168 Managing Time