Skip to main content

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.

Filter by
Sorted by
Tagged with
819 votes
13 answers
627k views

What killed my process and why?

My application runs as a background process on Linux. It is currently started at the command line in a Terminal window. Recently a user was executing the application for a while and it died ...
sbq's user avatar
  • 8,229
716 votes
13 answers
640k views

How do I capture SIGINT in Python?

I'm working on a python script that starts several processes and database connections. Every now and then I want to kill the script with a Ctrl+C signal, and I'd like to do some cleanup. In Perl I'd ...
James Thompson's user avatar
466 votes
35 answers
443k views

What's the best way to send a signal to all members of a process group?

I want to kill a whole process tree. What is the best way to do this using any common scripting languages? I am looking for a simple solution.
Adam Peck's user avatar
  • 7,005
308 votes
11 answers
250k views

How to prevent SIGPIPEs (or handle them properly)

I have a small server program that accepts connections on a TCP or local UNIX socket, reads a simple command and (depending on the command) sends a reply. The problem is that the client may have no ...
jkramer's user avatar
  • 15.7k
288 votes
11 answers
169k views

Is it possible to capture a Ctrl+C signal (SIGINT) and run a cleanup function, in a "defer" fashion?

I want to capture the Ctrl+C (SIGINT) signal sent from the console and print out some partial run totals.
Sebastián Grignoli's user avatar
209 votes
9 answers
279k views

Catch Ctrl-C in C

How does one catch Ctrl+C in C?
Feldor's user avatar
  • 2,101
169 votes
4 answers
179k views

How can I catch a ctrl-c event?

How do I catch a Ctrl+C event in C++?
Scott's user avatar
  • 5,245
168 votes
9 answers
83k views

What is the difference between sigaction and signal?

I was about to add an extra signal handler to an app we have here and I noticed that the author had used sigaction() to set up the other signal handlers. I was going to use signal(). To follow ...
Matthew Smith's user avatar
158 votes
5 answers
92k views

What is the difference between SIGSTOP and SIGTSTP?

Just wondering about the difference between SIGSTOP and SIGTSTP signals.
user1419715's user avatar
  • 1,737
150 votes
6 answers
66k views

What does `kill -0 $pid` in a shell script do?

Basically, what signal does '0' represent, because here I see SIGNAL numbers starting from 1.
gjain's user avatar
  • 4,488
150 votes
2 answers
90k views

Signal handling with multiple threads in Linux

In Linux, what happens when a program (that possibly has multiple threads) receives a signal, like SIGTERM or SIGHUP? Which thread intercepts the signal? Can multiple threads get the same signal? Is ...
user avatar
119 votes
7 answers
49k views

In what order should I send signals to gracefully shutdown processes?

In a comment on this answer of another question, the commenter says: don’t use kill -9 unless absolutely necessary! SIGKILL can’t be trapped so the killed program can’t run any shutdown ...
system PAUSE's user avatar
  • 38.1k
114 votes
18 answers
141k views

Can I send a ctrl-C (SIGINT) to an application on Windows?

I have (in the past) written cross-platform (Windows/Unix) applications which, when started from the command line, handled a user-typed Ctrl-C combination in the same way (i.e. to terminate the ...
Matthew Murdoch's user avatar
100 votes
8 answers
51k views

How to avoid using printf in a signal handler?

Since printf is not reentrant, it's not supposed to be safe to use it in a signal handler. But I've seen lots of example codes that uses printf this way. So my question is: when do we need to avoid ...
Yu Hao's user avatar
  • 121k
98 votes
7 answers
177k views

How to suspend/resume a process in Windows?

In Unix we can suspend a process execution temporarily and resume it with signals SIGSTOP and SIGCONT. How can I suspend a single-threaded process in Windows without programming ?
Michael's user avatar
  • 41.8k
98 votes
3 answers
68k views

How can I catch SIGSEGV (segmentation fault) and get a stack trace under JNI on Android?

I'm moving a project to the new Android Native Development Kit (i.e. JNI) and I'd like to catch SIGSEGV, should it occur (possibly also SIGILL, SIGABRT, SIGFPE) in order to present a nice crash ...
Chris Boyle's user avatar
  • 11.5k
97 votes
3 answers
61k views

Calling pthread_cond_signal without locking mutex

I read somewhere that we should lock the mutex before calling pthread_cond_signal and unlock the mutex after calling it: The pthread_cond_signal() routine is used to signal (or wake up) another ...
B Faley's user avatar
  • 17.8k
96 votes
3 answers
93k views

Catch Ctrl+C / SIGINT and exit multiprocesses gracefully in python [duplicate]

How do I catch a Ctrl+C in multiprocess python program and exit all processes gracefully, I need the solution to work both on unix and windows. I've tried the following: import multiprocessing import ...
zenpoy's user avatar
  • 19.9k
88 votes
9 answers
53k views

What is the correct way to make my PyQt application quit when killed from the console (Ctrl-C)?

What is the correct way to make my PyQt application quit when killed from the console (Ctrl-C)? Currently (I have done nothing special to handle unix signals), my PyQt application ignores SIGINT (...
static_rtti's user avatar
  • 55.2k
86 votes
7 answers
45k views

Django: signal when user logs in?

In my Django app, I need to start running a few periodic background jobs when a user logs in and stop running them when the user logs out, so I am looking for an elegant way to get notified of a user ...
ssc's user avatar
  • 9,796
85 votes
6 answers
79k views

Where are core dumps written on Mac?

On Mac OS X, if I send SIGQUIT to my C program, it terminates, but there is no core dump file. Do you have to manually enable core dumps on Mac OS X (how?), or are they written to somewhere else ...
xyz's user avatar
  • 27.6k
85 votes
4 answers
35k views

POSIX threads and signals

I've been trying to understand the intricacies of how POSIX threads and POSIX signals interact. In particular, I'm interested in: What's the best way to control which thread a signal is delivered to (...
Donal Fellows's user avatar
84 votes
6 answers
56k views

Why can't Unix programs have signals with meaningful program defined names (rather than USR1, etc)?

Many Unix programs accept signals like USR1 and USR2. For example, to upgrade the executable for Nginx on the fly, you send kill -USR2. I understand that USR1 is a "user defined" signal, meaning that ...
Nathan Long's user avatar
83 votes
8 answers
109k views

Providing/passing argument to signal handler

Can I provide/pass any arguments to signal handler? /* Signal handling */ struct sigaction act; act.sa_handler = signal_handler; /* some more settings */ Now, handler looks like this: void ...
hari's user avatar
  • 9,605
83 votes
2 answers
42k views

How and why does QuickEdit mode in Command Prompt freeze applications?

I recently ran into an issue with Command Prompt on Windows where QuickEdit mode was enabled and clicking the window was selecting text and hanging a running program. This is, apparently, known ...
Whymarrh's user avatar
  • 13.4k
83 votes
7 answers
389k views

No overload matches this call. Type 'string' is not assignable to type 'Signals'

I am using typescript to build a microservice and handling signals as well. The code was working fine till a few days ago but recently it started throwing errors. Couldn't find a fix for the issue. ...
M A SIDDIQUI's user avatar
  • 2,154
77 votes
4 answers
76k views

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 ...
Dagang Wei's user avatar
75 votes
1 answer
36k views

Pusher vs Pubnub vs open source Socket.io / SignalR.net / Faye / jWebSocket [closed]

I'm evaluating Pusher and PubNub at the moment to enable bi-directional realtime communications between my primarily web clients and my servers. Both look impressive, with Pusher's docs seeming to be ...
Matthew O'Riordan's user avatar
72 votes
8 answers
25k views

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 ...
Brian M. Hunt's user avatar
72 votes
9 answers
111k views

How to capture Control+D signal?

I want to capture the Ctrl+D signal in my program and write a signal handler for it. How can I do that? I am working on C and using a Linux system.
user avatar
72 votes
10 answers
96k views

Android Fatal Signal 11

In the app I'm developing on Android, I keep getting a Fatal Signal 11 error. I think it's something to do with the way that I'm accessing the memory but I can't figure out what is causing it. Here's ...
Declan Greally's user avatar
71 votes
2 answers
72k views

Run one command after another, even if I suspend the first one (Ctrl-z)

I know in bash I can run one command after another by separating them by semicolons, like $ command1; command2 Or if I only want command2 to run only if command1 succeeds, using &&: $ ...
asmeurer's user avatar
  • 90k
70 votes
6 answers
64k views

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 ...
Dane Larsen's user avatar
  • 1,584
70 votes
3 answers
204k views

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's user avatar
  • 1,631
68 votes
2 answers
18k views

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 ...
Daniel Trebbien's user avatar
59 votes
4 answers
12k views

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 ...
poswald's user avatar
  • 1,785
59 votes
3 answers
64k views

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) { ...
Robb1's user avatar
  • 4,877
58 votes
6 answers
127k views

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 ...
57 votes
6 answers
64k views

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"...
Tilo Prütz's user avatar
  • 1,785
56 votes
13 answers
47k views

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 ...
Mo J. Mughrabi's user avatar
55 votes
4 answers
24k views

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. ...
Bastian's user avatar
  • 5,755
55 votes
7 answers
17k views

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 ...
StefanoP's user avatar
  • 3,868
51 votes
4 answers
45k views

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 ...
Vivek Maran's user avatar
  • 2,713
51 votes
1 answer
88k views

Debugging child process after fork (follow-fork-mode child configured)

I'm developing an application which the parent forks a child to handle certain tasks. I'm having an issue where I've configured gdb to follow-fork-mode child but after fork, after reaching a ...
ihsan's user avatar
  • 601
51 votes
3 answers
48k views

Capture SIGINT in Java

What is the best way to capture a kill signal in java without using JNI. I did discover the sun.misc.Signal and the sun.misc.SignalHandler and the warning of the possibility of being removed in the ...
Begui's user avatar
  • 2,826
50 votes
4 answers
33k views

Is Python variable assignment atomic?

Let's say I am using a signal handler for handling an interval timer. def _aHandler(signum, _): global SomeGlobalVariable SomeGlobalVariable=True Can I set SomeGlobalVariable without worrying ...
jldupont's user avatar
  • 95.9k
50 votes
8 answers
18k views

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 ...
WilliamKF's user avatar
  • 42.4k
50 votes
3 answers
18k views

Python: What is the default handling of SIGTERM?

What does Python do under the covers by default if it receives a SIGTERM but there is no signal handler registered for it?
meteoritepanama's user avatar
49 votes
5 answers
78k views

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? ...
imacake's user avatar
  • 1,713
49 votes
4 answers
43k views

How to send signal to program run in a docker container?

I have a program run in a docker container with detached mode. So how to send a signal such as SIGINT to this program?
atupal's user avatar
  • 17k

1
2 3 4 5
151