signal-handling

kill is unsafe respect to signals - any alternative?

試著忘記壹切 提交于 2019-12-11 15:18:33
问题 I read that kill is unsafe respect to signals here. What else should I use if I want to kill child process as part of clean up inside my signal handler? What are my alternatives? 回答1: You've misread, that page says that kill() (and everything else in the table) shall be async-signal-safe. anything not in the table is to be considered unsafe. 来源: https://stackoverflow.com/questions/6971201/kill-is-unsafe-respect-to-signals-any-alternative

Matlab: Is it possible to create signal handlers (.m scripts)

心不动则不痛 提交于 2019-12-11 03:18:35
问题 I've looked through the documentation, etc, but I'm not seeing anything obvious. I'd like to have a signal handler that can intercept ^C , ^\ , or some other keypress that could be used to interrupt a long-running script (each discrete computation is typically <1s) and allow it to exit gracefully and save current state. Matlab does have event handlers for COM, but it's windows-only and I'm in a *nix environment. If the answer is 'tough luck', I'm cool with that ... I'm just not seeing

Python - Handle CTRL+D with 'import signal'

不羁岁月 提交于 2019-12-11 02:07:58
问题 I can currently handle CTRL + C via: def hand_inter(signum, frame): print 'hey, nice job.' signal.signal(signal.SIGINT, hand_inter) However I am required to also handle CTRL + D yet cannot find the appropriate "signal.CTRL+D" call for signum. 回答1: Ctrl + D is not a signal, it's end of file. If you have an interactive program, you will be most probably reading STDIN and Ctrl + D is way how user says that the input is over. Outside this context it does not have any special meaning. The code

Managing Signal Handling for daemons that fork()

帅比萌擦擦* 提交于 2019-12-11 00:44:43
问题 I want to write a robust daemon in perl that will run on Linux and am following the template described in this excellent answer. However there are a few differences in my situation: First I am using Parallel::ForkManager start() and next ; to fork on an event immediately followed by exec('handle_event.pl') In such a situation, I have the following questions: Where should I define my signal handlers. Should I define them in the parent (the daemon) and assume that they will be inherited in the

How to change FPU context in signal handler (C++/Linux)

自作多情 提交于 2019-12-10 20:05:48
问题 I wrote a signal handler to catch FPE errors. I need to continue execution even if this happens. I receive a ucontext_t as parameter, I can change the bad operand from 0 to another value but the FPU context is still bad and I run into an infinite loop ? Does someone already manupulate the ucontext_t structure on Linux ? I finally found a way to handle these situations by clearing the status flag of ucontext_t like this: ... const long int cFPUStatusFlag = 0x3F; aContext->uc_mcontext.fpregs-

C++ exceptions and signal handlers

﹥>﹥吖頭↗ 提交于 2019-12-10 16:42:37
问题 I am reading The Design and Evolution of C++ , by Bjarne Stroustrup. Regarding exeception handling and asynchronous signals it is mentioned as below: Can exceptions be used to handle things like signals? Almost certainly not in most C environments. The trouble is that C uses functions like malloc that are not re-entrant. If an interrupt occurs in the middle of malloc and causes an exception, there is no way to prevent the exception handler from executing malloc again. A C++ implementation

Can I send SIGINT to a Python subprocess on Windows?

耗尽温柔 提交于 2019-12-10 14:49:21
问题 I've got a Python script managing a gdb process on Windows, and I need to be able to send a SIGINT to the spawned process in order to halt the target process (managed by gdb) It appears that there is only SIGTERM available in Win32, but clearly if I run gdb from the console and Ctrl+C, it thinks it's receiving a SIGINT. Is there a way I can fake this such that the functionality is available on all platforms? (I am using the subprocess module, and python 2.5/2.6) 回答1: Windows doesn't have the

Signal handler won't see global variable

北城以北 提交于 2019-12-10 05:45:11
问题 Here's the problem: this program should receive input from stdin and count the bytes inserted; the SIGUSR1 signal whill stop the main program and will print on file standard error how many bytes have been copied when I send the SIGUSR1. That's how my teacher wants me to do this: in one terminal type cat /dev/zero | ./cpinout | cat >/dev/null while from a second terminal send signals with kill -USR1 xxxx where xxxx is the pid of cpinout. I updated my previous code: /* cpinout.c */ #include

Installing signal handler with Python

泄露秘密 提交于 2019-12-08 03:49:42
问题 (there is a follow up to this question here) I am working on trying to write a Python based Init system for Linux but I'm having an issue getting signals to my Python init script. From the 'man 2 kill' page: The only signals that can be sent to process ID 1, the init process, are those for which init has explicitly installed signal handlers. In my Python based Init, I have a test function and a signal handler setup to call that function: def SigTest(SIG, FRM): print "Caught SIGHUP!" signal

Installing signal handler with Python

a 夏天 提交于 2019-12-07 15:24:33
(there is a follow up to this question here ) I am working on trying to write a Python based Init system for Linux but I'm having an issue getting signals to my Python init script. From the 'man 2 kill' page: The only signals that can be sent to process ID 1, the init process, are those for which init has explicitly installed signal handlers. In my Python based Init, I have a test function and a signal handler setup to call that function: def SigTest(SIG, FRM): print "Caught SIGHUP!" signal.signal(signal.SIGHUP, SigTest) From another TTY (the init script executes sh on another tty) if I send a