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
68
votes
3 answers

How to trigger SIGUSR1 and SIGUSR2?

I'm getting acquainted with signals in C. I can't figure out what kind of signals SIGUSR1 and SIGUSR2 are and how can I trigger them. Can anyone please explain it to me?
haunted85
  • 1,601
  • 6
  • 24
  • 40
68
votes
4 answers

How to trap exit code in Bash script

There're many exit points in my bash code. I need to do some clean up work on exit, so I used trap to add a callback for exit like this: trap "mycleanup" EXIT The problem is there're different exit codes, I need to do corresponding cleanup works.…
Dagang
  • 24,586
  • 26
  • 88
  • 133
67
votes
2 answers

How are asynchronous signal handlers executed on Linux?

I would like to know exactly how the execution of asynchronous signal handlers works on Linux. First, I am unclear as to which thread executes the signal handler. Second, I would like to know the steps that are followed to make the thread execute…
Daniel Trebbien
  • 38,421
  • 18
  • 121
  • 193
67
votes
8 answers

Get signal names from numbers in Python

Is there a way to map a signal number (e.g. signal.SIGINT) to its respective name (i.e. "SIGINT")? I'd like to be able to print the name of a signal in the log when I receive it, however I cannot find a map from signal numbers to names in Python,…
Brian M. Hunt
  • 81,008
  • 74
  • 230
  • 343
66
votes
6 answers

PyQt4.QtCore.pyqtSignal object has no attribute 'connect'

I'm having issues with a custom signal in a class I made. Relevant code: self.parse_triggered = QtCore.pyqtSignal() def parseFile(self): self.emit(self.parse_triggered) Both of those belong to the class: RefreshWidget. In its parent class I…
Dane Larsen
  • 1,534
  • 2
  • 18
  • 27
58
votes
4 answers

How do I prevent fixtures from conflicting with django post_save signal code?

In my application, I want to create entries in certain tables when a new user signs up. For instance, I want to create a userprofile which will then reference their company and some other records for them. I implemented this with a post_save…
poswald
  • 1,755
  • 1
  • 11
  • 11
57
votes
6 answers

How to stop 'uninterruptible' process on Linux?

I have a VirtualBox process hanging around which I tried to kill (KILL/ABORT) but without success. The parent pid is 1 (init). top shows the process as D which is documented as "uninterruptible sleep". strace shows up nothing. How can I get rid of…
Tilo Prütz
  • 1,766
  • 3
  • 16
  • 27
55
votes
13 answers

Accessing the user's request in a post_save signal

I have done the below post_save signal in my project. from django.db.models.signals import post_save from django.contrib.auth.models import User # CORE - SIGNALS # Core Signals will operate based on post def…
Mo J. Mughrabi
  • 6,747
  • 16
  • 85
  • 143
55
votes
3 answers

Checking if errno != EINTR: what does it mean?

I've found this piece of code used several times (also a similar one where it's used open() instead of write()). int c = write(fd, &v, sizeof(v)); if (c == -1 && errno != EINTR) { perror("Write to output file"); exit(EXIT_FAILURE); } Why it…
Robb1
  • 4,587
  • 6
  • 31
  • 60
55
votes
7 answers

How do I mock a django signal handler?

I have a signal_handler connected through a decorator, something like this very simple one: @receiver(post_save, sender=User, dispatch_uid='myfile.signal_handler_post_save_user') def signal_handler_post_save_user(sender, *args,…
StefanoP
  • 3,798
  • 2
  • 19
  • 26
55
votes
4 answers

Is Django post_save signal asynchronous?

I have a like function which is just like social networks like or thumbs up function; the user clicks the star / heart / whatever to mark the content as liked.It is done with ajax and must be fast. The only problem here is that for some reasons I…
Bastian
  • 5,625
  • 10
  • 44
  • 68
49
votes
5 answers

What is in Apache 2 a "caught SIGWINCH" error?

My server (ubuntu 8.04) LAMP running drupal 6, when there is high traffic, it stops serving pages. A restart of apache2 will not work, so I have to restart the service. I found this message in the apache2 error.log [notice] caught SIGWINCH,…
Geries
  • 21
  • 1
  • 4
  • 9
49
votes
8 answers

Under what circumstances are C++ destructors not going to be called?

I know that my destructors are called on normal unwind of stack and when exceptions are thrown, but not when exit() is called. Are there any other cases where my destructors are not going to get called? What about signals such as SIGINT or SIGSEGV?…
WilliamKF
  • 41,123
  • 68
  • 193
  • 295
48
votes
5 answers

Which signal does ctrl-x send when used in a terminal?

On Linux/Unix there are signals. The CtrlC one (SIGINT) is obvious to me. Now, in some other applications there are signals via CtrlX?! Is that even a signal or does it generate an escape sequence? Is there anything else I can use as something…
imacake
  • 1,703
  • 7
  • 18
  • 26
48
votes
4 answers

Signals and interrupts a comparison

Based on various references, my subjective definition of signals in Linux is "The triggers that are used to notify the processes about an occurrence of a specific event.Event here may refer to a software exception.Additionally signals may also be…
Vivek Maran
  • 2,623
  • 5
  • 38
  • 52