signals

trapping signals in a multithreaded environment

拜拜、爱过 提交于 2019-12-14 00:48:21
问题 I have a large program that needs to be made as resilient as possible, and has a large number of threads. I need to catch all signals SIGBUS SIGSEGV , and re-initialize the problem thread if necessary, or disable the thread to continue with reduced functionality. My first thought is to do a setjump , and then set signal handlers, that can log the problem, and then do a longjump back to a recovery point in the thread. There is the issue that the signal handler would need to determine which

Can I signal multiple threads simultaneously with pthread_cond_wait(,)?

偶尔善良 提交于 2019-12-13 23:37:51
问题 I am writing various code snippets and see what happens. The code below was intended to delay all threads until all reached a certain point in the code and then make each print a distinctive number. Since the threads all do that, the numbers should occur in a random order. My current problem is that I keep they threads busy waiting. If the number of threads gets big, the program slows down significantly. I would like to change that by using signals, I found pthread_cond_wait() for that,

Can a parent process determine if its child has received a SIGINT?

一笑奈何 提交于 2019-12-13 22:08:14
问题 Suppose, I launch a parent process, which launches a subprocess, but then the parent receives a SIGINT . I want the parent to exit, but I don't want the child process to linger and/or become a zombie. I need to make sure it dies. If I can determine that the child also received a SIGINT , then it is probably cleaning up on its own. In that case, I'd prefer to briefly wait while it finishes and exits on its own. But if it did not receive a SIGINT , then I will send it a SIGTERM (or SIGKILL )

Perl trapping Ctrl-C (sigint) in bash

﹥>﹥吖頭↗ 提交于 2019-12-13 19:13:25
问题 I'm reading How do we capture CTRL ^ C - Perl Monks, but I cannot seem to get the right info to help with my problem. The thing is - I have an infinite loop, and 'multiline' printout to terminal ( I'm aware I'll be told to use ncurses instead - but for short scripts, I'm more comfortable writing a bunch of printf s ). I'd like to trap Ctrl-C in such a way, that the script will terminate only after this multiline printout has finished. The script is (Ubuntu Linux 11.04): #!/usr/bin/env perl

Python close children when closing main process

孤人 提交于 2019-12-13 16:54:18
问题 I have have a main process that forks a number of subprocesses. I want to be able to kill these child processes off when my main process gets the kill signal. Ideally I would want to do something along the lines of: def handler(signum, frame, pid_list): log('Killing Process') for pid in pid_list: os.kill(pid, signal.SIGTERM) os.waitpid(pid, 0) # need sys.exit() if __name__ == "__main__": <code that creates child processes, pids> signal.signal(signal.SIGTERM, handler(pid_list)) But of course,

How to handle Win32 Application termination

橙三吉。 提交于 2019-12-13 15:34:22
问题 I have an Win32 application with no window written in C. My question is: is there any way to handle the termination of my application. Ex. closing it from the task manager or via the console. 回答1: It is unclear from the question, but if this is a console mode application then you can call SetConsoleCtrlHandler to install a callback that Windows will call just before it terminates your app. Beware that this callback runs on a separate thread and that you have to complete the callback function

Test cases in C for WIFSIGNALED, WIFSTOPPED, WIFCONTINUED

旧城冷巷雨未停 提交于 2019-12-13 15:09:59
问题 I'm playing with waitpid() and signal() and I'm looking for reliable test cases for returning WIFSIGNALED(status) = WIFSTOPPED(status) = WIFCONTINUED (status) = true but can't find any... Care to tell me how can I make sure those return true so I can debug my code? Also, a few hints about what signals should I catch with signal() to test those macros would be helpful... 回答1: #include <errno.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> #include <sys/wait.h> #include <unistd.h>

cases in which SIGKILL will not work

ぐ巨炮叔叔 提交于 2019-12-13 13:20:11
问题 Are there any cases where an application running on linux, which has not blocked signal SIGKILL, will not get killed on firing SIGKILL signal ? 回答1: SIGKILL cannot be blocked or ignored ( SIGSTOP can't either). A process can become unresponsive to the signal if it is blocked "inside" a system call (waiting on I/O is one example - waiting on I/O on a failed NFS filesystem that is hard-mounted without the intr option for example). (Another side case is zombie processes, but they're not really

CTRL+C doesn't interrupt call to shared-library using CTYPES in Python

雨燕双飞 提交于 2019-12-13 13:02:33
问题 When calling a loop being performed in a C shared-library (dynamic library), Python will not receive a KeyboardInterrupt, and nothing will respond (or handle) CTRL+C. What do I do? 回答1: Unless you use PyDLL or PYFUNCTYPE ; the GIL is released during the ctypes calls. Therefore the Python interpreter should handle SIGINT by raising KeyboardInterrupt in the main thread if the C code doesn't install its own signal handler. To allow the Python code to run in the main thread; you could put the

Extract certain numbers of samples from left to right given index point of a signal in Matlab

↘锁芯ラ 提交于 2019-12-13 11:19:08
问题 There is a matrix Idx = [1xM] with M dimension of index numbers of a signal to be extracted. For each index number, from left to right certain numbers of samples should be extracted to form a new sub-signal of original signal. For example, 3 samples from left and 4 samples from right of an index number see below: [idx-3:idx+4] [New_Sig] becomes an one-row matrix instead of being the same dimension of index number from index matrix [Idx] Fs = 500; %Frequency:500 StartIdx = 0.150 * Fs; EndIdx =