signals

(Unit) Test python signal handler

别说谁变了你拦得住时间么 提交于 2019-12-11 04:09:04
问题 I have a simple Python service, where there is a loop that performs some action infinitely. On various signals, sys.exit(0) is called, which causes SystemExit to be raised and then some cleanup should happen if it can. In a test, i.e. standard unittest.TestCase , I would like to test that this cleanup happens and the loop exits. However, I'm stuck on even getting the signal to be triggered / SystemExit to be raised. # service.py import signal import sys import time def main(): def signal

FM signal strength of Android

和自甴很熟 提交于 2019-12-11 03:36:46
问题 I want to know the FM Radio signal strength in Android. For this I have to interact with hardware or not? Or is there any API which can directly give me the value of signal strength? 回答1: FM radio is available in some phones. Anyways you must have an FM tuner (radio) built-in. For this I have to interact with hardware or not? Yes, of course you will have to as it has not been brought into the stack. is there any API which can directly give me the value of signal strength? I think, NO. Maybe

pthread_exit in signal handler causes segmentation fault

我与影子孤独终老i 提交于 2019-12-11 03:34:44
问题 The program below sets SIG_ALRM handler for the whole process, creates a thread, sends SIG_ALRM signal to new created thread. In SIG_ALRM handler pthread_exit is called. The result - segmentation fault. If you sleep before sending signal - OK. It looks like new thread has not been started at the moment of pthread_exit. I tried to locate segmentation fault with gdb but couldn't reproduce the crash with gdb. What causes segmentation fault? Thanks! #include <signal.h> #include <pthread.h>

Sending signals to a process opened by proc_open()

末鹿安然 提交于 2019-12-11 03:28:46
问题 We've got a utility here that's using proc_open() to call ssh to run commands on a remote machine. However, in some cases we need to halt the command on the remote machine but proc_close() and proc_terminate() do not cause the desired signal to be sent through to the far side of the ssh connection. SSH will generally issue a SIGHUP to running programs when it is terminated, but we need to send a SIGINT to ssh which will forward it through to the program running on the remote end. I've googled

How are different signals handled in python

大城市里の小女人 提交于 2019-12-11 03:27:59
问题 I am using python 2.7 version on ubuntu. I am curious regarding how different signals are handled in python program during its execution. Is there any priority based selection.? For eg: If there are two different signals generated at the same time, which one will be served first? In my program given below it waits for the user to press Ctrl-C key, if done so it will display "Process can't be killed with ctrl-c key!". Along with this it keep generating an SIGALRM signal every second and keeps

Which signal was delivered to process deadlocked in signal handler

无人久伴 提交于 2019-12-11 03:14:41
问题 I have a core dump from a process that deadlocked after invoking a signal handler. How do I determine which signal was delivered and who sent it? The GDB-generated backtrace for the the thread that received the signal follows. The signal handler was called in frame 15. (gdb) bt #0 0x00007fa9c204654b in sys_futex (w=0x7fa9c2263d80, value=2, loop=<value optimized out>) at ./src/base/linux_syscall_support.h:1789 #1 base::internal::SpinLockDelay (w=0x7fa9c2263d80, value=2, loop=<value optimized

delegate SIGINT signal to child process and then cleanup and terminate the parent

老子叫甜甜 提交于 2019-12-11 02:59:44
问题 I have a main python(testmain.py) script that executes another python script(test.py) using subprocess.Popen command. When I press Ctrl-C , I want the child to exit with exit code 2 and then the parent to display that exit code and then terminate . I have signal handlers in both parent and child scripts. testmain.py def signal_handler(signal, frame): print "outer signal handler" exit(2) signal.signal(signal.SIGINT, signal_handler) def execute() proc=subprocess.Popen("python test.py",shell

Sending signal to thread from annother non-process and logging stack not happening

混江龙づ霸主 提交于 2019-12-11 02:56:20
问题 I am trying to send signal to a POSIX thread from another process (Not from the process that created that thread. What I did to send signal using kill(...):: int trap_handle(pid_t child_waited ) 69 { 70 printf("%s, new value: %d, child_waited=<%ld>\n", __func__,g_var_x, child_waited); 71 int errno_ = -1; 72 errno_ = kill(child_waited, SIGUSR1); 73 //syscall(SYS_tgkill, -1, child_waited, SIGUSR1); 74 //errno_ = pthread_kill(child_waited, SIGUSR1); 75 if(0==errno_) 76 printf("Signal sent to

Not able to catch SIGINT signal while using select()

末鹿安然 提交于 2019-12-11 02:48:06
问题 I had defined my own signal handler for SIGINT. But my signal handler doesn't get called The signal handler just terminates the program. But on pressing ctrl+c, the program doesn't quit. Please help... This is how the code looks.. sa.sa_handler = handle_termsig; sa.sa_flags = 0; sigemptyset(&sa.sa_mask); sigaction(SIGINT, &sa, 0); sigaction(SIGTERM, &sa, 0); sigemptyset(&g_termsigs); sigaddset(&g_termsigs, SIGINT); sigaddset(&g_termsigs, SIGTERM); sigprocmask(SIG_BLOCK, &g_termsigs, 0); if

handling sigterm in OSx

*爱你&永不变心* 提交于 2019-12-11 02:42:07
问题 I have console C++ application built in XCode 6 and want to add SIGTERM handler to it. There are a lot of examples, but I can't get them to work. #include <csignal> namespace { volatile std::sig_atomic_t gDone = 0; } static void term_handler(int i) { gDone = 1; } int main(int argc, const char * argv[]) { std::signal(SIGTERM, term_handler); while (!gDone); return 0; } The debugger stopped on the while statement, but the handler was not called. The same problem with this code #include <signal.h