signals

How does sig_atomic_t actually work?

给你一囗甜甜゛ 提交于 2019-12-17 10:44:59
问题 How does the compiler or OS distinguish between sig_atomic_t type and a normal int type variable, and ensures that the operation will be atomic? Programs using both have same assembler code. How extra care is taken to make the operation atomic? 回答1: sig_atomic_t is not an atomic data type. It is just the data type that you are allowed to use in the context of a signal handler, that is all. So better read the name as "atomic relative to signal handling". To guarantee communication with and

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

狂风中的少年 提交于 2019-12-17 10:22:31
问题 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? 回答1: Are there any other circumstances where they

Understanding scipy deconvolve

守給你的承諾、 提交于 2019-12-17 09:35:09
问题 I'm trying to understand scipy.signal.deconvolve. From the mathematical point of view a convolution is just the multiplication in fourier space so I would expect that for two functions f and g : Deconvolve(Convolve(f,g) , g) == f In numpy/scipy this is either not the case or I'm missing an important point. Although there are some questions related to deconvolve on SO already (like here and here) they do not address this point, others remain unclear (this) or unanswered (here). There are also

Throwing an exception from within a signal handler

元气小坏坏 提交于 2019-12-17 09:33:28
问题 We have a library that deals with many aspects of error reporting. I have been tasked to port this library to Linux. When running though my little test suite, one of the tests failed. A simplified version of the test appears below. // Compiler: 4.1.1 20070105 RedHat 4.1.1-52 // Output: Terminate called after throwing an instance of 'int' abort #include <iostream> #include <csignal> using namespace std; void catch_signal(int signalNumber) { signal(SIGINT, SIG_DFL); throw(signalNumber); } int

Kill or terminate subprocess when timeout?

醉酒当歌 提交于 2019-12-17 08:53:07
问题 I would like to repeatedly execute a subprocess as fast as possible. However, sometimes the process will take too long, so I want to kill it. I use signal.signal(...) like below: ppid=pipeexe.pid signal.signal(signal.SIGALRM, stop_handler) signal.alarm(1) ..... def stop_handler(signal, frame): print 'Stop test'+testdir+'for time out' if(pipeexe.poll()==None and hasattr(signal, "SIGKILL")): os.kill(ppid, signal.SIGKILL) return False but sometime this code will try to stop the next round from

Run one command after another, even if I suspend the first one (Ctrl-z)

断了今生、忘了曾经 提交于 2019-12-17 08:11:06
问题 I know in bash I can run one command after another by separating them by semicolons, like $ command1; command2 Or if I only want command2 to run only if command1 succeeds, using && : $ command1 && command2 This works, but if I suspend command1 using Ctrl-z , in the first case, it runs command2 immediately, and in the second case, it doesn't run it at all. How can I run commands in sequence, but still be able to suspend the first command, but not have the second run until I have restarted it

Why can't capture SIGSEGV using signalfd?

孤街醉人 提交于 2019-12-17 07:41:25
问题 My system is ubuntu 12.04. I modify the example from man 2 signalfd , and add sigaddset(&mask, SIGSEGV) in the exmaple. But I can't get the output when SIGSEGV is generated. Is it a bug of glibc ? The fragment of source code is following: sigemptyset(&mask); sigaddset(&mask, SIGINT); sigaddset(&mask, SIGQUIT); sigaddset(&mask, SIGSEGV); /* Block signals so that they aren't handled according to their default dispositions */ if (sigprocmask(SIG_BLOCK, &mask, NULL) == -1) handle_error(

Simple Linux Signal Handling

偶尔善良 提交于 2019-12-17 07:13:54
问题 I have a program that creates many threads and runs until either power is shutdown to the embedded computer, or the user uses kill or ctrl c to terminate the process. Here's some code and how the main() looks. static int terminate = 0; // does this need to be volatile? static void sighandler(int signum) { terminate = 1; } int main() { signal(SIGINT, sighandler); // ... // create objects, spawn threads + allocate dynamic memory // ... while (!terminate) sleep(2); // ... // clean up memory,

Signal handling in pthreads

此生再无相见时 提交于 2019-12-17 07:13:48
问题 I have created a pthread, and installed a signal handler inside that, same way as we do in main( ) function. The thread's signal handler is a separate function. Surprisingly, it is not working, that is the thread's signal handler is not able to catch signals. Here is the code: #include <pthread.h> #include <unistd.h> #include <sys/types.h> #include <stdio.h> #include <signal.h> typedef struct data { char name[10]; int age; }data; void sig_func(int sig) { printf("Caught signal: %d\n",sig);

How do I prevent fixtures from conflicting with django post_save signal code?

被刻印的时光 ゝ 提交于 2019-12-17 07:12:29
问题 In my application, I want to create entries in certain tables when a new user signs up. For instance, I want to create a userprofile which will then reference their company and some other records for them. I implemented this with a post_save signal: def callback_create_profile(sender, **kwargs): # check if we are creating a new User if kwargs.get('created', True): user = kwargs.get('instance') company = Company.objects.create(name="My Company") employee = Employee.objects.create(company