Real-Time Applications with RTLinux

RTLinux gives you a hard real-time, low-level environment when you need it--and all the power and flexibility of Linux when you don't.
Listing 2. Using the rtlinux_sigaction Function
#include <rtlinux_signal.h>
#define IRQ 7
void my_handler(int);
struct rtlinux_sigaction sig, oldsig;
float old_time=0.0;
float new_time=0.0;
float omega=10.0;
        /* spin speed */
int main(void)
     old_time = <sampleclock>;
     /* capture IRQ 7 and execute my_handler
        each time that IRQ 7 arrives: */
     sig.sa_handler = my_handler;
     sig.sa_flags = RTLINUX_SA_PERIODIC;
     rtlinux_sigaction( irq, & sig, & oldsig )
    /* the main part of our program: we wish to
       plot information as long as the rotor is
       still spinning */
        printf("Omega = %.1f\n",omega); 
              /* to stdout */
             /* via fancy plotting package*/
    /* We are no longer spinning,
       let's clean up after ourselves... */
    /* free the irq: */
    sig.sa_handler = RTLINUX_SIG_IGN;
    rtlinux_sigaction( IRQ, & sig, & oldsig );
    /* exit gracefully */
    return 0;
void my_handler(int argument)
     /* calculate spin speed here */
new_time= <sampleclock>;
     omega = 1.0/(new_time - old_time);
     old_time = new_time;


rtlinux_sigaction(), identifies the function my_handler() as the function that we wish to execute each time that IRQ 7 is triggered. Note that ``RTLINUX_SA_PERIODIC'' tells rtlinux_sigaction() to reset itself and wait for the next signal over and over again--otherwise the signal handler would be executed exactly once. Then the while() loop in our program both prints out and plots the latest spin speed. Finally, when the spin speed drops to below 1Hz, the program begins the shutdown process, which involves the deregistering my_handler() as our signal handler.

The job of my_handler() is straightforward: calculate the spin speed. The accuracy of this calculation should be quite high because each time that IRQ 7 is triggered, the handler is called as quickly as the underlying hardware allows.

Regardless of which scheme we use to implement Task 2, the most important thing to note is the amazing versatility and elegance that the RTLinux programming environment provides.


The design compromises that make Linux such a powerful general-purpose OS render it less than ideal for hard and even soft real-time applications. By decoupling real-time and non-real-time processes, RTLinux harnesses the best of both worlds: on the one hand, it offers a high-performance, strictly deterministic real-time application environment, while on the other, it offers the rich programming environment, large application and user base, and powerful networking power of Linux. Most importantly, all improvements made to Linux by its huge development community become instantly available to RTLinux users.

RTLinux is open-source software distributed under the GPL. Further information is available at the FSMLabs web site ( and the software is freely available for download from the FSMLabs ftp server ( There are working versions for x86 (uni-processor and SMP), Alpha, PowerPC (uni-processor only), and PC-104 (via miniRTL). Both source and RPM packages are available.