signals

Signal handling in C - interrupt in interrupt

。_饼干妹妹 提交于 2019-11-28 13:42:35
I was wondering if it is possible to be interrupted by a signal when my program is handling other signal at the same time, I tried to simulate it with: #include<signal.h> #include<stdlib.h> #include<stdio.h> #include<unistd.h> #include<sys/wait.h> #include<string.h> void sig_output() { sigset_t set; sigprocmask(0,NULL,&set); printf("currently blocking:"); if (sigismember(&set,SIGUSR1)) printf("\nSIGUSR1"); if(sigismember(&set,SIGUSR2)) printf("\nSIGUSR2"); printf("\n"); return ; } void sig_handler(int sig) { raise(SIGUSR1); printf("start\n"); if (sig==SIGUSR1) printf("SIGUSR1\n"); else if (sig

Running startup code right after Django settings? (also for commands)

别等时光非礼了梦想. 提交于 2019-11-28 13:36:09
I am using mongoengine and would like to run connect() after settings (not inside them as suggested in its docs ). This is actually more like a general question how to run code right after all settings are loaded. Update: I need a solution for management commands as well. Common approach is adding a middleware with exception MiddlewareNotUsed or adding code to root urls.py, but both don't work for commands. The normal place for startup-like code is in a urls.py (when you need the settings to be already loaded). Django doesn't have a good spot yet for this. (There is an "app refactor" branch

Detect when console application is closing/killed?

牧云@^-^@ 提交于 2019-11-28 13:16:28
I wanted to make a safe exit for my console application that will be running on linux using mono but I can't find a solution to detect wether a signal was sent to it or the user pressed ctrl+c. On windows there is the kernel function SetConsoleCtrlHandler which does the job but that doesnt work on mono. How do I get a closing event on my console application to safe exit it ? You need to use Mono.UnixSignal , there's a good sample posted by Jonathan Pryor : http://www.jprl.com/Blog/archive/development/mono/2008/Feb-08.html There's also a shorter example on Mono page: FAQ / Technical / Operating

how to intercept linux signals ? (in C)

喜夏-厌秋 提交于 2019-11-28 12:46:20
I need to intercept and trace signals from any binaries, like strace does it under linux. I don't need a so verbose output like the real one strace. I just want to know how it works, how can I intercept signal and how can I trace them. Thanks in advance :) strace uses the ptrace() system call for tracing, which also allows you to intercept (and possibly manipulate) signals sent to the process. Here's a tiny example: #include <sys/ptrace.h> #include <unistd.h> #include <sys/types.h> #include <sys/wait.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> int main(int argc, char **argv)

do actions on end of execution

风流意气都作罢 提交于 2019-11-28 12:20:16
I have an http server (launched using http.Handle ) and I would like to do some operations. How can I do that (on linux) ? Is it possible to do those operations in case of a ctrl-C ? I'm not familiar with unix signals so the answer may be trivial. You can subscribe to the TERM and INT signals using the signal package. But note that these signals are only sent when the process is killed explicitly; normal exit (initiated by the process itself) does not involve any sort of signals. I think for normal exit just do something in the main routine (which supposedly should spawn worker goroutines and

PyQt signal with arguments of arbitrary type / PyQt_PyObject equivalent for new-style signals

孤街醉人 提交于 2019-11-28 12:10:18
I have an object that should signal that a value has changed by emitting a signal with the new value as an argument. The type of the value can change, and so I'm unsure of how to write the signal type. I know that I can acconmplish this using old-style signals like this: self.emit(SIGNAL("valueChanged(PyQt_PyObject)"), newvalue) but how would I write this using new-style signals? I am aware of a previous question related to this but no "real" answer was given there. First, the object you're emitting from needs the signal defined as an attribute of its class : class SomeClass(QObject):

How to send a signal to a process in C?

烈酒焚心 提交于 2019-11-28 12:04:18
I need to send a signal to a process and when the process receives this signal it does some things, how is this best achieved in C? The way to send a signal to a process is kill(pid, signal); However, you should be aware that signals are not a robust means of inter-process communication except for parent-to-direct-child messages due to inherent race conditions. Pipes, files, directories, named semaphores, sockets, shared memory, etc. all provide greatly superior approaches to inter-process communication. wildplasser If you happen to be on one of the Unix variants, the following man pages will

struct sigaction incomplete error

荒凉一梦 提交于 2019-11-28 12:01:37
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, /* signal number whose action will be changed */ &act, /* new action to do when SIGCHLD arrives*/ NULL); /*

Explicitly invoke SIG_DFL/SIG_IGN handlers on Linux

非 Y 不嫁゛ 提交于 2019-11-28 11:55:47
问题 I've blocked, and then waited for a signal via the following code: sigset_t set; sigfillset(&set); // all signals sigprocmask(SIG_SETMASK, &set, NULL); // block all signals siginfo_t info; int signum = sigwaitinfo(&set, &info); // wait for next signal struct sigaction act; sigaction(signum, NULL, &act); // get the current handler for the signal act.sa_handler(signum); // invoke it The last line generates a segmentation fault, as the handler is set to SIG_DFL (defined as 0 ). How can I

what's the order of post_save receiver in django?

烂漫一生 提交于 2019-11-28 10:54:43
问题 You can bind multiple post_save(pre_save, etc) receivers to a class. Is there a way to specify the ordering of receipt of signals? 回答1: Ordering signal in django would be a good feature but unfortunately Django does not support this as mentioned in this ticket although you can have a close look at Django Signals and the Observer Design Pattern to have better understanding of its pattern & design. 来源: https://stackoverflow.com/questions/20990146/whats-the-order-of-post-save-receiver-in-django