signals

SIGIO arriving for file descriptors I did not set it for and when no IO is possible

﹥>﹥吖頭↗ 提交于 2019-12-17 21:59:44
问题 I am trying to receive a signal when I/O is possible on a file descriptor. The program needs to be doing something else when it is not doing I/O, so using select(2) is not an option. When I run the sample code is below, it is printing the message from inside the handler as fast as it can, even when there is no data on stdin. Even weirder is that the file descriptor reported in the siginfo_t structure varies from run to run. I only set it up for stdin (fd 0); why would the handler report any

Python: How to prevent subprocesses from receiving CTRL-C / Control-C / SIGINT

好久不见. 提交于 2019-12-17 21:49:22
问题 I am currently working on a wrapper for a dedicated server running in the shell. The wrapper spawns the server process via subprocess and observes and reacts to its output. The dedicated server must be explicitly given a command to shut down gracefully. Thus, CTRL-C must not reach the server process. If I capture the KeyboardInterrupt exception or overwrite the SIGINT-handler in python, the server process still receives the CTRL-C and stops immediately. So my question is: How to prevent

struct sigaction incomplete error

谁都会走 提交于 2019-12-17 19:37:57
问题 Although including <signal.h> I get an error saying that struct sigaction is an incomplete type. I have no Idea what to do with it. Please help #include <signal.h> struct sigaction act; int main(int argc, char** argv) { int depth; /* validate arguments number*/ if(argc < 2) { printf("fatal error: please use arguments <MaxChild> <MaxDepth>\n"); exit(1); } /* register the realtime signal handler for sigchld*/ /*173*/ memset(&act,0,sizeof(act)); act.sa_handler = sigproc; sigaction(SIGCHLD, /*

GTK detecting window resize from the user

╄→гoц情女王★ 提交于 2019-12-17 19:33:31
问题 In GTK (or pygtk or gtkmm...) How can I detect that an application window has been manually resized by the user, as is typically done by dragging the window's edge? I need to find a way to differentiate manual resizes from resizes that originate from gtk, such as changes in window content. 回答1: Have you tried connecting to the GDK_CONFIGURE event? Check out this example under the "Moving window" section. The example shows a callback doing something when the window is moved, but the configure

Sending Signals to a Running JVM

孤者浪人 提交于 2019-12-17 18:45:08
问题 I'm using a custom signal handler to catch TERM, ABRT and INT signals in a custom java daemon. I have this handler in the code so that I can send TERM signals to it and gracefully shutdown the program via the kill command. The signal handler works right now, but when I compile the code I'm receiving the following warning (many times over): warning: sun.misc.SignalHandler is Sun proprietary API and may be removed in a future release while using these classes: import sun.misc.SignalHandler;

GDB: Ctrl+C doesn't interrupt process as it usually does but rather terminates the program

Deadly 提交于 2019-12-17 18:13:04
问题 Normally when you run a program through GDB you can press Ctrl+C to interrupt it, e.g. if it gets stuck in an infinite loop and you want to get a backtrace. I'm debugging a program (xmms2d as it happens) but in this program only, when I press Ctrl+C it gets treated as if GDB was not running - the program shuts down cleanly and then GDB tells me the program exited normally. How do I get the usual GDB behaviour back, where Ctrl+C interrupts the program? Or is there another way to produce the

Signal Handling in C

让人想犯罪 __ 提交于 2019-12-17 17:51:40
问题 How can I implement signal Handling for Ctrl-C and Ctrl-D in C....So If Ctrl-C is pressed then the program will ignore and try to get the input from the user again...If Ctrl-D is pressed then the program will terminate... My program follows: int main(){ char msg[400]; while(1){ printf("Enter: "); fgets(msg,400,stdin); printf("%s\n",msg); } } Thanks, Dave 回答1: When dealing with POSIX signals, you have two means at your disposal. First, the easy (but deprecated) way, signal(). Second, the more

Linux: Why is sig_atomic_t typedef'ed to int?

南楼画角 提交于 2019-12-17 16:43:17
问题 On my Linux box, sig_atomic_t is a plain old int . Do ints posses a special atomic quality? $ gcc -v Using built-in specs. Target: x86_64-linux-gnu ... Thread model: posix gcc version 4.3.2 (Debian 4.3.2-1.1) $ echo '#include <signal.h>' | gcc -E - | grep atomic typedef int __sig_atomic_t; typedef __sig_atomic_t sig_atomic_t; 回答1: C99 sig_atomic_t conforms only to a very weak definition of "atomicity", because C99 has no concept of concurrency , only interruptibility. (C2011 adds a

how in BOOST send a signal in a thread and have the corresponding slot executed in another thread?

时光毁灭记忆、已成空白 提交于 2019-12-17 15:51:45
问题 In Qt for instance if you emit a signal in a thread other that the GUI thread, the signal is enqueued and executed later in the GUI thread, is there a way to do that with boost? thanks 回答1: For an event loop use boost::asio::io_service. You can post tasks inside this object and have another thread execute them, in a thread safe way: struct MyClass { boost::io_service service; void doSomethingOp() const { ... } void doSomething() { service.post(boost::bind(&MyClass::doSomethingOp, this)); }

Is Python variable assignment atomic?

ⅰ亾dé卋堺 提交于 2019-12-17 15:48:11
问题 Let's say I am using a signal handler for handling an interval timer. def _aHandler(signum, _): global SomeGlobalVariable SomeGlobalVariable=True Can I set SomeGlobalVariable without worrying that, in an unlikely scenario that whilst setting SomeGlobalVariable (i.e. the Python VM was executing bytecode to set the variable), that the assignment within the signal handler will break something? (i.e. meta-stable state) Update : I am specifically interested in the case where a "compound assignment