Questions tagged [signals]

A signal is a notification to a process that an event occurred. Signals are sometimes described as software interrupts. Signals are analogous to hardware interrupts in that they interrupt the normal flow of execution of a program; in most cases, it is not possible to predict exactly when a signal will arrive. They are defined in the C standards and extended in POSIX, but many other programming languages/systems provide access to them as well.

Standards

These standards actually place requirements on the signal-handling facilities:

C++11 essentially says that you get the same facilities as in C, as long as you restrict signal handlers to the common subset of C and C++, and use C linkage for them. Quoting n3242 section 18.10 "Other runtime support" [support.runtime] (paragraph 8),

The common subset of the C and C++ languages consists of all declarations, definitions, and expressions that may appear in a well formed C++ program and also in a conforming C program. A POF (“plain old function”) is a function that uses only features from this common subset, and that does not directly or indirectly use any function that is not a POF, except that it may use functions defined in Clause 29 that are not member functions. All signal handlers shall have C linkage. A POF that could be used as a signal handler in a conforming C program does not produce undefined behavior when used as a signal handler in a C++ program. The behavior of any other function used as a signal handler in a C++ program is implementation-defined.

7326 questions
3
votes
1 answer

Catching SIGTERM in C

I'm trying to learn how to catch sigterm for a larger assignment I have in class. I'm following the steps in this tutorial however it doesn't work for me. When I enter the command "kill [process id]" the sleep doesn't stop and just continues. I've…
user2466886
  • 205
  • 1
  • 3
  • 14
3
votes
2 answers

Qt signals inheritance?

EDIT: I provided an answer but I'd be happy to accept another one that provides an explanation. I subclassed QPushButton to add some functionality, but after connection the clicked signal to a slot, it doesn't get called. If I use a vanilla…
Tamás Szelei
  • 23,169
  • 18
  • 105
  • 180
3
votes
1 answer

parent shell not getting SIGINT when child has a handler

When you press Ctrl-C, foreground processes receive SIGINT: $ bash -c 'sleep 100; echo program died' ^C $ echo $? 130 However, if a program installs a SIGINT handler, parent program doesn't receive the signal. Why? #include #include…
basin
  • 3,949
  • 2
  • 27
  • 63
3
votes
3 answers

Why doesn't SIGVTALRM trigger inside time.sleep()?

I'm trying to use SIGVTALRM to snapshot profile my Python code, but it doesn't seem to be firing inside blocking operations like time.sleep() and socket operations. Why is that? And is there any way to address that, so I can collect samples while…
David Wolever
  • 148,955
  • 89
  • 346
  • 502
3
votes
2 answers

How to get id of process from which came signal in Python?

Please see following Python code: def Handler(signum, frame): #do something signal.signal(signal.SIGCHLD, Handler) Is there a way to get process ID from which signal came from? Or is there another way to get process ID from which signal came…
Ivan Kolesnikov
  • 1,787
  • 1
  • 29
  • 45
3
votes
1 answer

How to handle OS signal in a python program?

I am writing a python program which reads from a queue through a infinite while loop. How can I handle signal sent by OS / Keyboard interrupt(CTRL+C) to break from the while loop and close active connections and files and exit the program gracefully…
Siddharth Gupta
  • 1,573
  • 9
  • 24
3
votes
1 answer

How to handle several same unblocked signals in Python?

Please see following python code: signal.pthread_sigmask(signal.SIG_BLOCK, range(1, signal.NSIG)) #block signals time.sleep(60) #waiting 60 seconds pending = signal.sigpending() #check how much signals in pending state When application is sleep I…
Ivan Kolesnikov
  • 1,787
  • 1
  • 29
  • 45
3
votes
3 answers

How to broadcast a signal in Qt4

I'm wanting a paradigm in a Qt4 (PyQt4) program where a component is able to respond to a signal without knowing anything about where it is coming from. My intial reading suggests that I have to explicitly connect signals to slots. But what I want…
Chris Crook
  • 243
  • 3
  • 7
3
votes
4 answers

terminate script of another user

On a linux box I've got a python script that's always started from predefined user. It may take a while for it to finish so I want to allow other users to stop it from the web. Using kill fails with Operation not permitted. Can I somehow modify my…
clorz
  • 1,103
  • 3
  • 14
  • 30
3
votes
2 answers

When can a running process in Unix receive a SIGTRAP (value 5) signal?

There is a one process called NSM in my code. Which abruptly got a SIGTRAP signal and it got killed. So just wanted to know that when can a process get a SIGTRAP signal?
3
votes
1 answer

What is real use of return type of signal function

Signal function return the value of old handler , but what is the situation where old handler value may useful, because most of the places we don't check return value of signal function.
pankaj kushwaha
  • 369
  • 5
  • 20
3
votes
1 answer

Terminate sudo python script when the terminal closes

How can I tell if the terminal running my python script was closed? I want to safely end my python script if the user closes the terminal. I can catch SIGHUP with a handler, but not when the script is run as sudo. When I start the script with sudo…
peteey
  • 420
  • 4
  • 14
3
votes
2 answers

What is the zero signal?

I was looking into a nagios plugin and I found this code: killall -0 $1 I tried this and it returned 0 for a running process, but it did not kill the process. Please explain the meaning of this 0 value and why it did not kill the process.
3
votes
1 answer

Django: m2m_changed not fired when end of relation is deleted

NOTICE: due to production environment constraints, I must stick to django-1.4 for the moment. I've just made a test to see whether I can hook onto an event when ManyToMany changes. I have a Group model that holds several Item objects. Whenever the…
Olivier H
  • 835
  • 2
  • 8
  • 26
3
votes
1 answer

c Signal Handler

I am writing an application wherein I want call a function every 1 second. This is what I've written so far Timerspec.it_interval.tv_sec=1; Timerspec.it_interval.tv_nsec=0; Timerspec.it_value.tv_sec=1; Timerspec.it_value.tv_nsec=0; timer_t…
Harry
  • 2,177
  • 1
  • 19
  • 33
1 2 3
99
100