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
4 answers

Calling script from java, sigpipe signal received

I am encountering some weird behavior when calling a shell script from a Java process. Process p = Runtime.getRuntime().exec("mybashscript.sh"); (new StreamGobblerThread(p.getInputStream())).start(); (new…
Will
  • 1,622
  • 4
  • 25
  • 39
3
votes
2 answers

How can I receive custom signals in python?

I'm writing a python program (in Linux, on a Raspberry Pi) to run as a daemon (using python-daemon) and I understand the 'runner' component will soon be deprecated. For this reason, I'd like for the daemon to react to signals - for which I intend…
Ryan Hunt
  • 76
  • 1
  • 3
3
votes
2 answers

Status of threads when signal handler runs

Assume a multi-threaded application, with a signal handler defined in it. Now if a signal is delivered to the PROCESS, and signal handler is invoked - My doubt is what happens to other threads during the period signal handler is running. Do they…
ultimate cause
  • 2,264
  • 4
  • 27
  • 44
3
votes
1 answer

What is the purpose of function pointer returned by signal() function?

So, I've used signal() function several times so far, although I haven't been aware of what, actually, declaration of this function looks like. I found out that this function returns pointer to a function: void (*signal(int sig, void…
Vel
  • 524
  • 3
  • 11
3
votes
0 answers

About unix signals: sigsuspend() and race condition

This is the coursework of my class. I'm not sure whether my answer is correct or not. Can someone give me any instruction. In the first question, I can't figure out why there is a race condition, is my explanation wrong? #include #include…
walkcc
  • 301
  • 4
  • 17
3
votes
1 answer

System Calls in C signals and fork

Hi I've this problem to solve with a functional program in C. "Write a C program where a process F create a childprocess C. The childprocess C waits the user to type the password, if is correct sends a signal SIGUSR1 to the father, if after 3…
Dave
  • 1,912
  • 4
  • 16
  • 34
3
votes
1 answer

Windows: Handle segfaults in all threads

I'm looking for a way to catch segfaults and other errors anywhere in a program (which uses multiple threads, some of which are created by external libraries). I'm using Visual Studio 2013 with the Intel C++ Compiler 2015. Some external DLL's - in…
3
votes
3 answers

Linux Shutdown and Java Shutdown Hook

When I run a Java process in background and I shut down the computer (ArchLinux), will the computer wait some seconds for the termination of my shutdown-hook in Java?
Harald
  • 526
  • 4
  • 26
3
votes
2 answers

Python: Pass more than two arguments in signal

I know what when I use signals there are two arguments (signum and frame). But what if I want to send more? For example: object for self. How can I do it? example: def terminate_handler(signum, frame, self): …
Guy Markman
  • 426
  • 1
  • 4
  • 14
3
votes
2 answers

Perl signal handlers are reset in END blocks

This works as expected since Perl 5.10.1: SIGINTs are trapped. #!/usr/bin/perl use strict; use warnings; $SIG{INT} = sub { die "Caught a sigint $!" }; sleep(20); But here SIGINTs are not trapped. #!/usr/bin/perl use strict; use…
gxtaillon
  • 1,016
  • 1
  • 19
  • 33
3
votes
1 answer

What do you think about NResponder?

I was on the point of start using AS3 Signals for my new project because Native Events has a bad reputation, and then I found this: http://code.google.com/p/nineveh-responder/ But I couldn't find more information (in addition to official docs and…
Enrique
  • 4,693
  • 5
  • 51
  • 71
3
votes
1 answer

How can I interrupt an infinite sigtimedwait?

My program has an event loop disciplined by epoll (for I/O) and condition variables (for other message activity), as well as a worker thread responsible for catching signals (SIGINT, SIGTERM, SIGHUP). SIGINT, SIGTERM, SIGHUP and SIGPIPE are blocked…
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
3
votes
1 answer

Exactly which variables need to be sig_atomic_t in the context of signal handling?

Here is a simple toy program that uses volatile sig_atomic_t. #include #include #include #include #define UNUSED(x) (void) (x) volatile sig_atomic_t quit; void sigusr1_handler(int sig) { …
Lone Learner
  • 18,088
  • 20
  • 102
  • 200
3
votes
2 answers

How to interrupt python multithreaded app?

I'm trying to run the following code (it i simplified a bit): def RunTests(self): from threading import Thread import signal global keep_running keep_running = True signal.signal( signal.SIGINT, stop_running…
Roman Prykhodchenko
  • 12,655
  • 8
  • 29
  • 33
3
votes
1 answer

interrupt python multiprocessing.Process using signals in Windows

I have a python script that spawns a new Process using multiprocessing.Process class. This process is supposed to run forever to monitor stuff. On Unix I can now use os.kill() to send a signal to that specific process and signal.signal(...) within…
cima
  • 63
  • 1
  • 5