Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5943539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:24:37+00:00 2026-05-22T16:24:37+00:00

I have a process p registered with a signal handler for SIGALRM . A

  • 0

I have a process p registered with a signal handler for SIGALRM. A timer is setup to periodically send signal SIGALRM to process p. There are also multiple threads running in process p. Is the signal handler, when being triggered and executed, un-preemptible? Or to say, is it that the execution of signal handler will not be interrupted by any thread in process p?

PS: I thought signal handler is executed in kernel (is it?) and kernel is unpreemptive to user-mode threads? Correct me if it’s wrong…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:24:37+00:00Added an answer on May 22, 2026 at 4:24 pm

    Pretty much – don’t – dealing with shared data in a signal handler almost always leads to a world of pain, dealing with threads as well and you got yourself a mess.

    By default a signal is blocked while the signal handler is running (at least on linux, that might not be universally true), so at least the signal handler will not be preempted by itself. Though, if you have multiple threads, and the signal is not blocked in the other threads, a signal handler might very well be run concurrently within several threads.

    One thread will receive the signal and execute the handler, it’s more or less random which thread that’ll be, although you could control it by blocking the signal in all threads you don’t want to handle the signal.

    However, any of the other threads bar the one handling the signal might run in parallell. The thread handling a signal could run the signal handler at pretty much any point in the program (as long as the signal isn’t blocked.) So, you’d need some sort of locking to protect that data. The problem is you can’t use any of the normal thread locking primitives, they are not signal async safe. Meaning if you e.g. try to grab a pthread_mutex_t in a signal handler, you easily deadlock your program.

    The only functions you can safely call in a signal handler are the ones listed here .
    With regards to protecting the shared data, you could use sigblock()/sigunblock() as a sort of protection, ensuring the signal handler doesn’t run while you’re accessing that shared data – and the signal have to blocked in all the threads, otherwise it’ll just run within one of the threads that doesn’t have it blocked – going down that road is madness.

    Pretty much the only shared data you can safely access in a signal handler is a sig_atomic_t type, in practice other kinds of primitive types usually safe too.

    What you really should do in a signal handler is just

    • set a global flag
    • check that flag elsewhere in code when suitable, and take action

    Or

    • have some sort of main loop that monitors file descriptors for events using select()/poll() or similar.
    • create a pipe and monitor that in your main loop
    • write() a byte to a pipe in your signal handler
    • run your code to deal with the signal, including protecting any shared data when the mainloop detects an event on that pipe

    Or

    • Keep a spare thread around
    • block the given signal in all your threads
    • have that spare thread loop on calling sigsuspend() with a signal mask ensuring delivery of that signal.
    • run your code, including protecting any shared data to deal with the signal when sigsuspend() returns
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a critical process running in java (1.6), with a registered shutdown hook.
Anybody out there have experience testing out of process assemblies? I'm testing some Com+
There is a timer which sends out signal SIGALARM every 1 sec. A signal
I need to send a message to a globally registered process, that might be
I have a process that runs in a thread (used as a realtime signal
I have created a process where a (registered) user can upload (after client-side and
I have a service running in its own process. It appears fine in the
i have the process page for login, i can connected to DB and also
I have Process objects that are monitored from two different views. A Windows.Forms.ListView (actually
I have 1 process that receives incoming connection from port 1000 in 1 linux

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.