LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   using the timer interrupt (https://www.linuxquestions.org/questions/programming-9/using-the-timer-interrupt-16154/)

bos 03-13-2002 01:57 AM

using the timer interrupt
 
Hi,

I have a (hopefully) small question:

I need my code to execute every time tick.
How can i use the timer interrupt? Do I need to share it with the timer (as I've seen in /proc/interrupt, timer uses the timer interrupt)?

Thanks

lavelle 03-15-2002 10:38 AM

I don't know what language you are using so I'll show you a perl example. Perl is simpler as you don't need to set signal masks.

What you are probably looking for is the alarm call do a man alarm to see how to use the system call. Basically you tell the OS to send you an ALRM signal in X number of seconds then make sure your program will catch that signal when it arrives.

Here is an example in Perl:

#!/usr/bin/perl

sub alarm
{
print "Are you done yet\n";
alarm(10); #reschedule the alarm in 10 seconds
}

$SIG{ALRM}=\&alarm; #assign the signal handler
alarm(5);
print "Type something in then press enter\n";
<STDIN>; #read and throw away user input


All times are GMT -5. The time now is 04:59 PM.