Find the answer to your Linux question:
Results 1 to 10 of 10
HI,, i am using sigaction() to handle the SIGALRM generated by setitimer() . how can i disable the SIGALRM and re-enable it ,assuming i have finished executing the handler and ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Dec 2007
    Posts
    29

    SIGALARM disable


    HI,,
    i am using sigaction() to handle the SIGALRM generated by setitimer().

    how can i disable the SIGALRM and re-enable it ,assuming i have finished executing the handler and during the running of setitimer() and before its timer expiration??
    ??
    thanks
    Last edited by raedbenz; 07-13-2008 at 09:14 AM. Reason: typo

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    how can i disable the SIGALRM and re-enable it
    There are two ways.
    1. Use sigaction() (or signal(), if you must) to ignore SIGALRM. See the man pages; use SIG_IGN as the signal handling function name.

      Then use sigaction() or signal() to re-establish your function handler when you want to heed the signal again.
    2. Faster code, and simpler:

      Have a global which is normally set to zero. When you want to ignore SIGALRM, set the global to one. When you want to heed the signal again, set the global to zero.

      Then your signal handler can check the global. If it's nonzero, just return without doing anything.

    Hope this helps.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  3. #3
    Just Joined!
    Join Date
    Dec 2007
    Posts
    29
    thanks,
    which one of the two methods the OS executes faster?
    raed

  4. #4
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    which one of the two methods the OS executes faster?
    My guess is that it won't make much difference, unless your intervals are extremely short or you disable the signal extremely often.

    If your intervals are extremely short, it's likely that method 1 will work faster. If you disable the signals extremely often, it's likely that method 2 will work faster.

    There are so many variables introduced by the rest of your program, and by the operating environment provided by the rest of the hardware, that it's especially important to test both ways yourself. Don't be surprised if you don't get a significant difference between the two.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  5. #5
    Just Joined!
    Join Date
    Dec 2007
    Posts
    29

    prioritize!!

    Quote Originally Posted by wje_lf View Post
    If your intervals are extremely short, it's likely that method 1 will work faster. If you disable the signals extremely often, it's likely that method 2 will work faster.
    Hi thanks for your replies.
    when running a function from user space, how can i tell the kernel scheduler to give high priority to this function or to be executed first in order to not miss the deadlines ?? is there a system call or c-lib functions?
    thanks

  6. #6
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    If you just want a way for it to work "most of the time", do this at the command line:
    Code:
    man 2 nice
    If man pages are not installed on your system, google this:
    Code:
    Linux man nice
    and concentrate on search results which discuss the system call, not the shell command.

    You'll find that to bump the priority of your process, you'll need to be root.

    On the other hand, if you want a guarantee of top priority execution, you'll need to use a real-time Linux kernel. For more information about real-time Linux, google this:
    Code:
    real-time Linux
    --
    Bill

    Old age and treachery will overcome youth and skill.

  7. #7
    Just Joined!
    Join Date
    Dec 2007
    Posts
    29
    thanks again,,maybe with an example things are easier:
    (I am intending not to use RT-Linux, the idea is to make my applications as real as possible without RT-Linux)
    what i have done is using the setitimer() system call to generate a signal (SIGALRM) each 1sec and catch the signal by a handler that prints the "hello world".

    what i want is give high priority for the function that prints "hello world" i.e printf(), or high priority for my setitimer(). does this system call do the job : sched_setscheduler()????
    thanks

  8. #8
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    what i want is give high priority for the function that prints "hello world" i.e printf(), or high priority for my setitimer(). does this system call do the job : sched_setscheduler()?
    Yes, unless you want that scheduling to be absolutely guaranteed; that is, unless your product will die a horrible death if the scheduling fails at rare intervals to work as you ask.

    In that case, you need a realtime Linux kernel.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  9. #9
    Just Joined!
    Join Date
    Dec 2007
    Posts
    29

    elaboration

    Quote Originally Posted by wje_lf View Post
    unless your product will die a horrible death if the scheduling fails at rare intervals to work as you ask.

    In that case, you need a real time Linux kernel.
    thanx again, could u plz elaborate more for me thie above statement??
    what do u mean by "your product"
    thanks

  10. #10
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    What do you mean by "your product"?
    I mean the program, or set of programs, you're writing.
    --
    Bill

    Old age and treachery will overcome youth and skill.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •