Problem
I am trying to write a program to use POSIX timers and am having the following problems:
A. When the POSIX timer program is compiled, the compiler fails
with errors relating to undefined symbols, which are contained
in the header file <sys/sudstime.h>. For example:error: undefined symbol: timer_t error: undefined symbol: CLOCK_REALTIME error: undefined symbol: TIMER_ABSTIME
I have to add "-D_POSIXTIMERS" on the compiler command line in order for this header file to be correctly included and for the compilation to succeed.
This is not documented in the development system documentation.
B. When I run the resulting program, the timer_create(S) routine fails with errno(S) set to ENOSYS (Intro(S)) which indicates "Function not implemented".
C. The manual page for timer_create(S) states that the
'sigev_notify' field passed to this routine call can be set to
"SIGEV_SIGNAL". However, when I try to compile a program that
specifies this flag value, the compilation fails with:error: undefined symbol: SIGEV_SIGNALD. I want to set a POSIX timer with an absolute clock value. However, it is unclear from the manual page for timer_settime(S) how I can determine what absolute value the POSIX timers actually use.
E. If the program is blocking upon a system call, for example
select(S) or read(S), no signal is received until the system
call returns. This behavior differs from using alarm(S), where
the SIGALRM signal that is generated is always received by the
calling process. Solution
A. Currently, if you want to develop code to use POSIX timers, the code must be compiled with the "-D_POSIXTIMERS" option in order to ensure that the necessary POSIX timer definitions are included from the system header files.
This problem has been reported to SCO Engineering.
B. The library routine timer_create(S) returns ENOSYS ("Function
not implemented") because this routine requires the use of the
"suds" driver (hence the linking of the libsuds library on the
cc command line). By default, the "suds" driver is not included
in the kernel, but this can be changed by editing the file:/etc/conf/sdevice.d/sudsModify the entry:suds N 1 0 0 0 0 0 0 0to:suds Y 1 0 0 0 0 0 0 0Then relink the kernel and reboot the system to enable the suds driver; IEEE timer operations will now be implemented.
Note that you may get a warning on reboot about the AIO driver not being included in your kernel but this warning can be ignored. If you do want to include the AIO driver, then execute the "mkdev aio" command to configure this driver accordingly.
C. Currently, only the use of SIGEV_NONE for the 'sigev_notify' field for timer_create(S) is supported for POSIX timers.
This problem has been reported to SCO Engineering.
D. The absolute clock value that the POSIX timers use for internal purposes is the number of clock ticks since the system was last booted. This value is actually held in a kernel variable called 'lbolt'. Although this variable is not easily accessible to programs running in user-space, the current 'lbolt' value is always returned by the library routine times(S).
The attached example program demonstrates how to create and use POSIX timers with absolute time.
---------------------------<cut here>-------------------------------/* ptimer.c
*
* cc -D_POSIXTIMERS -o ptimer ptimer.c -lsuds
*/#include <stdio.h>
#include <signal.h>
#include <sys/types.h>
#include <time.h>
#include <sys/times.h>
#include <unistd.h>#define START_DELAY 10
#define TIMER_PERIOD 2
#define NUM_OF_SIGS 5int count=0;void signal_handler(int sig) { printf("\n***caught signal %d (type: #%d)***\n", ++count, sig); }
time_t get_lbolt()
{
struct tms buffer;return times(&buffer);
}main()
{
time_t lbolt; /* time in HZ since last boot */
int Hz; /* clock ticks per second */
timer_t timer_id;
struct itimerspec ItimerSpec;
struct sigaction sigs;
time_t current_time;setbuf(stdout, NULL);printf("\n*******************************************************\n");
printf("This program which will wait for _%d_ seconds, and then\n",
START_DELAY);
printf("receive _%d_ SIGALRM signals every _%d_ seconds\n",
NUM_OF_SIGS, TIMER_PERIOD);
printf("before exiting.\n");
printf("*******************************************************\n\n");Hz = sysconf(_SC_CLK_TCK);sigs.sa_handler = signal_handler; /* point to handler function */
sigemptyset(&sigs.sa_mask); /* initialize */if (sigaction(SIGALRM, &sigs, (struct sigaction *) NULL) != 0) { perror("sigaction"); exit(1); }
if (timer_create(CLOCK_REALTIME, (struct sigevent *) NULL, &timer_id) != 0) { perror("timer_create()"); exit(1); }
lbolt = get_lbolt();/* printf("lbolt: %ld, Hz: %ld\n", lbolt, Hz); */ItimerSpec.it_value.tv_sec = START_DELAY + lbolt/Hz;
ItimerSpec.it_value.tv_nsec = 0;/* Reload value */ ItimerSpec.it_interval.tv_sec = TIMER_PERIOD; ItimerSpec.it_interval.tv_nsec = 0;
if (timer_settime(timer_id, TIMER_ABSTIME, &ItimerSpec, NULL) != 0) { perror("timer_settime()"); exit(1); }
printf("Waiting...\n");while (count < NUM_OF_SIGS) ;printf("\n...Exiting\n");}
---------------------------<cut here>-------------------------------E. Currently, a signal generated by a POSIX timer can only be received by a process while that process is running in user-mode.
This means that while the process is blocked upon a system call, that is, in kernel mode, it will not receive any POSIX timer- generated signals.
Upon return from a blocked system call, that is, returning from kernel-mode to user-mode, when the process is executed by the CPU, any pending signals of this type will then be delivered to this process.
This behavior is scheduled to be corrected in a future release of SCO OpenServer.
Currently, SCO Support recommends that you instead investigate using itimers (getitimer(S), setitimer(S)) for this type of development.