LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-28-2021, 05:28 AM   #1
s0n1c
LQ Newbie
 
Registered: Jul 2021
Posts: 2

Rep: Reputation: Disabled
Interrupt source


Hello forum,

I'm pretty new to this kind of programming and need some help:

I generate an interrupt on raspbian using struct itimerval for the timer and struct sigaction (see https://man7.org/linux/man-pages/man2/sigaction.2.html) for the signal generating an interrupt. The member sigaction.sa_handler seems to be a pointer to a function, some kind of interrupt service routine like used on Arduinos. The function needs one integer as input and I wonder what this is. Can anyone tell me if there is a list or something to determine the exact source of the interrupt?

Regards
s0n1c
 
Old 07-28-2021, 06:25 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,852
Blog Entries: 1

Rep: Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868
In 'struct sigaction' you can use either 'sa_handler' or 'sa_sigaction', but not both of them. Also you have to use flag SA_SIGINFO in field sa_flags accordingly.
Example1:
Code:
    static void handler (int signo) {
        [I only have 'signo']
    }

    int main (void) {
        struct sigaction siga;

        memset (&siga, 0, sizeof siga);
        siga.sa_handler= handler;

        sigaction (SIGsomething, &siga, NULL);
        ...
    }
Example2:
Code:
    static void handler3 (int signo, siginfo_t *info, void *ucontext) {
        [I have 'signo' and 'info', also 'ucontext' whatever it is]
    }

    int main (void) {
        struct sigaction siga;

        memset (&siga, 0, sizeof siga);
        siga.sa_sigaction= handler3;
        siga.sa_flags |= SA_SIGINFO;

        sigaction (SIGsomething, &siga, NULL);
        ...
    }
 
3 members found this post helpful.
Old 07-28-2021, 06:28 AM   #3
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,882

Rep: Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988
The int passed as an argument to a signal handler is the signal number (i.e. type) that caused it to be invoked. If a signal handler is only attached to a single signal, then it's pretty much redundant information.

The sigaction(3) man-page documents this, and you can find the signal numbers on signal(7).
 
5 members found this post helpful.
Old 07-28-2021, 09:29 AM   #4
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,882

Rep: Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988
I've never had need of the fancier SA_SIGINFO variant, but perhaps one day a use-case will present itself.
 
1 members found this post helpful.
Old 07-29-2021, 12:53 AM   #5
s0n1c
LQ Newbie
 
Registered: Jul 2021
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thank you, this solved my problem!!!
 
2 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Kernel panic: killing interrupt handler! In interrupt handler - not syncing. divyashree Programming 26 05-15-2010 01:27 PM
control is not going to interrupt handler when interrupt remyasj LinuxQuestions.org Member Intro 1 11-12-2009 12:56 AM
control is not going to interrupt handler when interrupt comes in serial driver sateeshalla Linux - Kernel 1 05-04-2006 09:43 AM
<0>Kernel panic: Aiee, killing interrupt handler! In interrupt handler - not syncing mrb Linux - Newbie 2 01-09-2005 09:47 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration