signals

In C++ when interrupted with ctrl-c call a function with arguments (other than signal number) before dying

强颜欢笑 提交于 2019-12-12 07:38:37
问题 I want to write a few extra lines to a file when interrupted with ctrl-c before the program dies. However the location of the file is not hard coded so I need something more than normal interrupt handling as explained here. What is the best way to do this? Motivation: I'm doing time dependent finite element simulations. Sometimes I forget or mis-estimate a reasonable tmax and the simulation would take a very long time to complete, so I interrupt it with ctrl-c. However I still want to use the

Signal Handling in UNIX

£可爱£侵袭症+ 提交于 2019-12-12 06:58:57
问题 After registering to handle a signal. In the signal handler function is it necessary to call signal() again to re-register? 回答1: Check this answer. Or particularly this link. Basically it depends on the model (BSD or System V) your unix system follows. Extract from signal man page. In the original Unix systems, when a handler that was established using signal() was invoked by the delivery of a signal, the disposition of the signal would be reset to SIG_DFL, and the system did not block

Why can't the signal handler in the child process be triggered?

六眼飞鱼酱① 提交于 2019-12-12 05:42:01
问题 My intention is to create a time out of 1 sec for fgets. If no input is received in 1 sec, then the program terminates. The design I come up with is: the parent registers a signal handler for SIGALRM. Then it forks a child which will trigger SIGALRM and it goes ahead and call fgets. The SIGALRM will trigger the handler which kills the parent process. But when I execute this on a ubuntu 14.04 64-bit, the handler is not triggered and the program just waits for user to input for fgets forever.

Sending signal from parent to child and vice-versa

那年仲夏 提交于 2019-12-12 04:18:34
问题 I am trying to practice signals and was trying to achieve below things 1) Child and parent prints 10 numbers and passes the baton to other 2) Parent/Child wait for there turn through sigsuspend 3) sigaction is just for heck of it to catch the signal 4) kill is used send the signal with respective process id However the output is marred with race-conditions and I see once parent gets signal from child control is never handed back to child Also I expected sigaction to catch the signal as well

Python PyQt callback never runs - how to debug?

試著忘記壹切 提交于 2019-12-12 04:17:05
问题 I have a fairly complicated piece of code using PyQt4 and sometimes my signal callbacks simply never run. It seems to be related to where/when I register the callbacks, ie. self.someobj.somesig.connect(self.callback) . I can see in the debugger that the callback is connected and that the signal es emitted. The code is too large to post here, but I will try to summarize: class RC(QtCore.QObject): render_ready = QtCore.pyqtSignal(object) def __init__(self, pc, ...): super(RC, self).__init__()

IllegalArgumentException when trying to handle SIGBREAK in Hotspot JVM on Windows

白昼怎懂夜的黑 提交于 2019-12-12 03:46:39
问题 I'm trying to use the signal handling classes in the sun.misc package (as documented here) to handle SIGBREAK in Hotspot JVM on Windows so I can trigger shutdown on Ctrl+Break instead of just dumping threads. However, I'm running into a situation where it throws an IllegalArgumentException saying that SIGBREAK is already being handled by the OS or the VM when I try to set up the handler. This happens even when I run the JVM with the -Xrs flag which supposedly disables handling of the SIGBREAK

Linux and real-time signals

家住魔仙堡 提交于 2019-12-12 02:57:52
问题 I am trying to write simple program that uses real-time signals in Linux. But I encountered strange behaviour, first the code: #include<signal.h> #include<sys/types.h> #include<stdlib.h> #include<stdio.h> #include"errhandling.h" #include<string.h> #include<errno.h> #include<unistd.h> void baz(int sig,siginfo_t* info,void *context) { if (sig==SIGUSR1) printf("SIGUSR1 %d\n",info->si_value.sival_int); else if(sig==SIGRTMIN) printf("SIGRTMIN %d\n",info->si_value.sival_int); else printf("SIGRTMIN

How does a process executing in kernel space come to know of occurrence of unexpected (asynchronous) events?

拟墨画扇 提交于 2019-12-12 02:04:23
问题 I have two questions: 1) Kernel-space process : When a process is executing in kernel mode, it does not receive any signals. Instead a process puts itself in a wait-queue when it expects to receive completion of any event. Such as completion of an I/O event . The process does not do anything at this stage. Once the event is triggered, ( the kernel sets a trap ? Correct if wrong ) and finally the process is waked up and resumes execution. Above is the case for expected events or (synchronous).

Signal handler getting called in wrong thread

醉酒当歌 提交于 2019-12-12 01:57:36
问题 I want to know if its possible to interrupt main thread and ask it to execute some callback. The main thread should continue with what it was doing after completing the callback. For instance, we have 2 threads t1 and m1 (main thread). t1 will interrupt m1 (main thread) and ask it to call a function with some parameters. The m1 (main thread) will stop doing what it was doing before and will start executing the function. The after finishing the function, it will get back to what it was doing

Looking for guidance on a deadlock scenario

纵饮孤独 提交于 2019-12-12 01:52:29
问题 I have a program that spawns lots of children and runs for long periods of time. The program contains a SIGCHLD handler to reap defunct processes. Occasionally, this program freezes. I believe that pstack is indicating a deadlock scenario. Is that the proper interpretation of this output? 10533: ./asyncsignalhandler ff3954e4 lwp_park (0, 0, 0) ff391bbc slow_lock (ff341688, ff350000, 0, 0, 0, 0) + 58 ff2c45c8 localtime_r (ffbfe7a0, 0, 0, 0, 0, 0) + 24 ff2ba39c __posix_ctime_r (ffbfe7a0,