signals

Linux C: upon receiving a signal, is it possible to know the PID of the sender?

☆樱花仙子☆ 提交于 2019-11-27 13:15:46
问题 Suppose my C program handles SIGUSR1. When it receives the signal, is it possible to know who sent it? I.e,. to get the pid of that process? 回答1: Yes, if you use the sigaction call to set up your signal handler instead of signal . Doing so will let you set up a signal handler that takes three parameters: An int , for the signal number (just like signal ) A siginfo_t * , which is a structure containing all sorts of information about the source of the signal, including the pid of the sender if

Dealing With Asynchronous Signals In Multi Threaded Program

南笙酒味 提交于 2019-11-27 13:10:23
问题 The Linux Programming Interface Book has mentioned a method for dealing with asynchronous signals in a multi threaded program: All threads block all of the asynchronous signals that the process might receive. The simplest way to do this is to block the signals in the main thread before any other thread are created. Each subsequently created thread will inherit a copy of the main thread's signal mask. create a single dedicated thread that accepts incoming signals using sigwaitinfo() ,

signal queuing in C

给你一囗甜甜゛ 提交于 2019-11-27 12:52:51
I have a simple program under Linux which sends SIGUSR1 signal to its child process in a cycle. But when I send e.g. 10 signals, sometimes happens, that the child received only 3 of them. Last sent signal is always SIGUSR2 and that is received every time. Are the signals queuing, or when process didn't process the previous, it is simply overwritten? Is there a way I can send signals in a queue? What happens is the following: First signal received, namely SIGUSR1, handler is called and is running Second signal received, since handler from nr1 is still running, the signal nr2 gets pending and

Android Fatal Signal 11

懵懂的女人 提交于 2019-11-27 12:37:36
问题 In the app I'm developing on Android, I keep getting a Fatal Signal 11 error. I think it's something to do with the way that I'm accessing the memory but I can't figure out what is causing it. Any help will be much appreciated! Here's the LogCat: 05-02 23:47:17.618: D/dalvikvm(590): GC_FOR_ALLOC freed 68K, 4% free 6531K/6787K, paused 101ms 05-02 23:47:17.638: I/dalvikvm-heap(590): Grow heap (frag case) to 7.619MB for 1228816-byte allocation 05-02 23:47:17.738: D/dalvikvm(590): GC_CONCURRENT

Coming back to life after Segmentation Violation

家住魔仙堡 提交于 2019-11-27 11:58:06
问题 Is it possible to restore the normal execution flow of a C program, after the Segmentation Fault error? struct A { int x; }; A* a = 0; a->x = 123; // this is where segmentation violation occurs // after handling the error I want to get back here: printf("normal execution"); // the rest of my source code.... I want a mechanism similar to NullPointerException that is present in Java, C# etc. Note : Please, don't tell me that there is an exception handling mechanism in C++ because I know that,

How do I mock a django signal handler?

时光怂恿深爱的人放手 提交于 2019-11-27 11:53:54
问题 I have a signal_handler connected through a decorator, something like this very simple one: @receiver(post_save, sender=User, dispatch_uid='myfile.signal_handler_post_save_user') def signal_handler_post_save_user(sender, *args, **kwargs): # do stuff What I want to do is to mock it with the mock library http://www.voidspace.org.uk/python/mock/ in a test, to check how many times django calls it. My code at the moment is something like: def test_cache(): with mock.patch('myapp.myfile.signal

Simple Signals - C programming and alarm function

青春壹個敷衍的年華 提交于 2019-11-27 11:49:31
#include <stdio.h> #include <signal.h> void ALARMhandler(int sig) { signal(SIGALRM, SIG_IGN); /* ignore this signal */ printf("Hello"); signal(SIGALRM, ALARMhandler); /* reinstall the handler */ } int main(int argc, char *argv[]) { alarm(2); /* set alarm clock */ while (1) ; printf("All done"); } I expect the program to print "hello" after 2 seconds, but instead the output is "zsh: alarm ./a.out" Any idea what is going on? You're forgetting to set the alarm handler initially. Change the start of main() like: int main(int argc, char *argv[]) { signal(SIGALRM, ALARMhandler); ... Also, the signal

Why do you need a while loop while waiting for a condition variable

血红的双手。 提交于 2019-11-27 10:58:43
问题 Say you have this code pthread_mutex_lock(&cam->video_lock); while(cam->status == WAIT_DISPLAY) // <-- Why is this a 'while' and not an 'if'? pthread_cond_wait(&cam->video_cond, &cam->video_lock); pthread_mutex_unlock(&cam->video_lock); My question is, why do you need a while loop here. Wouldn't pthread_cond_wait just wait until the signalling thread signals cam_video_cond ? OK, I know you might have a case where cam->status is not equal to WAIT_DISPAY when pthread_cond_wait is called, but in

run code after transaction commit in Django

和自甴很熟 提交于 2019-11-27 10:57:15
问题 Is there any way to run some code after transaction commit in Django? I need to send some messages to a rabbitmq server for offline processing, but the message gets to the consumer before the Django transaction is commited. My message is sent in the post_save signal of the model. What I'm looking for is a similar mechanism, using signals or something else, that would execute code after the commit (and do nothing if the transaction fails). I haven't found any generic way of doing it in Django.

Under what circumstances are C++ destructors not going to be called?

筅森魡賤 提交于 2019-11-27 10:52:08
I know that my destructors are called on normal unwind of stack and when exceptions are thrown, but not when exit() is called. Are there any other cases where my destructors are not going to get called? What about signals such as SIGINT or SIGSEGV? I presume that for SIGSEGV, they are not called, but for SIGNINT they are, how do I know which signals will unwind the stack? Are there any other circumstances where they will not be called? stinky472 Are there any other circumstances where they[destructors] will not be called? Long jumps: these interfere with the natural stack unwinding process and