signals

Interrupting blocked read

主宰稳场 提交于 2019-12-03 11:45:14
问题 My program goes through a loop like this: ... while(1){ read(sockfd,buf,sizeof(buf)); ... } The read function blocks when it is waiting for input, which happens to be from a socket. I want to handle SIGINT and basically tell it to stop the read function if it is reading and then call an arbitrary function. What is the best way to do this? 回答1: From read(2) : EINTR The call was interrupted by a signal before any data was read; see signal(7). If you amend your code to look more like: cont = 1;

In a signal handler, how to know where the program is interrupted?

自古美人都是妖i 提交于 2019-12-03 11:29:34
On x86 (either 64-bit or 32-bit) Linux -- for example: void signal_handler(int) { // want to know where the program is interrupted ... } int main() { ... signal(SIGALRM, signal_handler); alarm(5); ... printf(...); <------- at this point, we trigger signal_handler ... } In signal_handler, how can we know we are interrupted at printf in main()? Use sigaction with SA_SIGINFO set in sa_flags. Prototype code: #define _GNU_SOURCE 1 /* To pick up REG_RIP */ #include <stdio.h> #include <signal.h> #include <assert.h> static void handler(int signo, siginfo_t *info, void *context) { const ucontext_t *con

I have an error in main.m “Thread 1: signal SIGABRT” How can I fix this?

馋奶兔 提交于 2019-12-03 11:19:04
问题 My code in the main.m file is as follows. I haven't changed it at all from when I started programming this app. #import <UIKit/UIKit.h> #import "rickAppDelegate.h" int main(int argc, char *argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([rickAppDelegate class])); } } I am getting the SIGABRT error on the 'return UIApplicationMain' line. My program is an app which displays a red button and when you press it, it plays a video. This error appeared after I

What is a signal in Unix?

混江龙づ霸主 提交于 2019-12-03 10:58:37
This comment confuses me: "kill -l generally lists all signals". I thought that a signal means a quantized amount of energy. [Added] Please, clarify the (computational) signal in Unix and the physical signal. Are they totally different concepts? [Added] Are there major differences between paradigms? Is the meaning the same in languages such as C, Python and Haskell? The signal seems to be a general term. hhh I cannot believe that people are not comparing things such as hardware and software or stressing OS at some points. Comparison between a signal and an interrupt : The difference is that

Who uses POSIX realtime signals and why?

时光怂恿深爱的人放手 提交于 2019-12-03 10:47:55
问题 I am not being flip I really don't get it. I just read a whole bunch of material on them and I can't figure out the use case. I am not talking talking so much about the API for which the advantages over things like signal() are clear enough. Rather it seems RT signals are meant to be user space generated but to what end? The only use seems to be a primitive IPC but everything points to them being a lousy form of IPC (e.g. awkward, limited information, not particularly efficient, etc). So

Making sure a Python script with subprocesses dies on SIGINT

 ̄綄美尐妖づ 提交于 2019-12-03 10:32:06
问题 I've got a command that I'm wrapping in script and spawning from a Python script using subprocess.Popen . I'm trying to make sure it dies if the user issues a SIGINT . I could figure out if the process was interrupted in a least two ways: A. Die if the wrapped command has a non-zero exit status (doesn't work, because script seems to always return 0) B. Do something special with SIGINT in the parent Python script rather than simply interrupting the subprocess. I've tried the following: import

Runtime error handling in Swift

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 10:15:34
I am fully aware that Swift doesn't have a try/catch mechanism to catch exceptions (OK, Swift 2.0 now supports them). I also understand that many API methods return a NSError that will be filled with an error object if something goes wrong. So please don't point me to this question: Error-Handling in Swift-Language But this still doesn't explain how to react to runtime errors in your own code, like array-out-of-bounds accesses or force-unwrapping an optional value that is nil. For example: var test: String? test = nil println(test!) //oops! or var arr = [0,1,2] for i = 0...3 { println(arr[i])

How to write Ctrl-C handler in Haskell?

风格不统一 提交于 2019-12-03 10:00:25
I tried the following approach: import System.Exit import System.Posix.Signals import Control.Concurrent (threadDelay) main :: IO () main = do installHandler keyboardSignal (Catch (do exitSuccess)) Nothing threadDelay (1000000000) But it only outputs: ^CTest.hs: ExitSuccess on Ctrl-C , instead of exiting. How should I do it properly? From the docs of installHandler : a handler is installed which will invoke action in a new thread when (or shortly after) the signal is received. and exitWith: Note: in GHC, exitWith should be called from the main program thread in order to exit the process. When

SIGHUP for reloading configuration

≯℡__Kan透↙ 提交于 2019-12-03 09:38:30
According to signal(7) , SIGHUP is used to detect hangup on controlling terminal or death of controlling process. However, I have come across a lot of OSS daemons(services) where SIGHUP is used to initiate a reload of configuration. Here are a few examples: hostapd , sshd , snort etc. Is this a standard(or a generally acceptable) way to implement a reload? If not, whats recommended? SIGHUP as a notification about terminal closing event doesn't make sense for a daemon, because deamons are detached from their terminal. So the system will never send this signal to them. Then it is common practice

How to stop SIGINT being passed to subprocess in python?

假装没事ソ 提交于 2019-12-03 09:10:35
问题 My python script intercepts the SIGINT signal with the signal process module to prevent premature exit, but this signal is passed to a subprocess that I open with Popen. is there some way to prevent passing this signal to the subprocess so that it also is not exited prematurely when the user presses ctrl-c? 回答1: You are able to re-assign the role of ctrl-c using the tty module, which allows you to manipulate the assignment of signals. Be warned, however, that unless you put them back the way