signals

Override Ctrl-C

霸气de小男生 提交于 2019-11-27 06:01:55
问题 I am supposed override the Ctrl C signal and use it to print a message. It is not supposed to end the program. What happens so far is that when Ctrl C is pressed it prints the message, but ends the program. When I asked my professor he told me to do this: You need to make your signal handler keep from continuing to process the signal. Right now the signal is being handled by your code and then going on to the parent handler. Is there a method I am supposed to add or do i need to move the

signals and slots in multilayered UI widgets

旧街凉风 提交于 2019-11-27 05:38:46
Let's say we have the follogin UI: +--------------------------+ |W1 +--------------+ | | |W2 | | | | +----------+ | | | | |W3 | | | | | +----------+ | | | | | | | +--------------+ | +--------------------------+ W3 is interested in a certain signal emited in W1 (or a level below, i.e. qApp). The idea is to develop W3 independently. But somebody has to do the signal/slot connection. What would be a good practice/recommended way of connecting the signal emited in W1 into slot in W3 if we want W3 not to know about any other widget, and we don't want W1 to know about W3 either? Solution 1: Connect

Which signal does ctrl-x send when used in a terminal?

旧街凉风 提交于 2019-11-27 05:16:42
问题 On Linux/Unix there are signals. The Ctrl C one ( SIGINT ) is obvious to me. Now, in some other applications there are signals via Ctrl X ?! Is that even a signal or does it generate an escape sequence? Is there anything else I can use as something similar to Ctrl C ( Ctrl V , Ctrl X ...)? If anyone has a clue, im familiar with C more than bash, but answers in both languages are appreciated! 回答1: To get all the terminal control character assignments: stty -a 回答2: There is possibly a

Why can't capture SIGSEGV using signalfd?

寵の児 提交于 2019-11-27 05:13:30
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("sigprocmask"); sfd = signalfd(-1, &mask, 0); if (sfd == -1) handle_error("signalfd"); int* a = NULL; for (;;) {

Python: Catch Ctrl-C command. Prompt “really want to quit (y/n)”, resume execution if no

我怕爱的太早我们不能终老 提交于 2019-11-27 04:02:46
I have a program that may have a lengthy execution. In the main module I have the following: import signal def run_program() ...time consuming execution... def Exit_gracefully(signal, frame): ... log exiting information ... ... close any open files ... sys.exit(0) if __name__ == '__main__': signal.signal(signal.SIGINT, Exit_gracefully) run_program() This works fine, but I'd like the possibility to pause execution upon catching SIGINT, prompting the user if they would really like to quit, and resuming where I left off in run_program() if they decide they don't want to quit. The only way I can

Is it valid to have multiple signal handlers for same signal?

一笑奈何 提交于 2019-11-27 03:52:16
问题 I have two shared libraries linked to my test application. Both of the libraries have signal handlers for SIGINT . Is it valid to have multiple signal handlers for same signal? Which order the handlers will execute when I generate a SIGINT signal? 回答1: As said by others, only one signal handler can be set, which is the last one. You would then have to manage calling two functions yourself. The sigaction function can return the previously installed signal handler which you can call yourself.

signal handling

天涯浪子 提交于 2019-11-27 03:40:52
问题 I'm just playing with signal in Mac OS X. Why does the following code not produce the default behavior of SIGSEGV after my signal handler has finished? Under Linux, the code works fine. #include <stdio.h> #include <signal.h> #include <stdlib.h> void err_crash(); void my_signal_handler (int signal) { fprintf(stderr, "signal == %i\n", signal); fflush(stderr); err_crash(); } void err_crash() { static int count= 0; if (count) signal(SIGSEGV, SIG_DFL); /* break recursion loop if we recursed */

Simple Linux Signal Handling

感情迁移 提交于 2019-11-27 03:34:53
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, close threads, etc. // ... signal(SIGINT, SIG_DFL); // is this necessary? } I'm wondering a few things: Is

Signal handling in pthreads

僤鯓⒐⒋嵵緔 提交于 2019-11-27 03:32:00
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); signal(SIGSEGV,sig_func); } void func(data *p) { printf("This is from thread function\n"); signal(SIGSEGV

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

£可爱£侵袭症+ 提交于 2019-11-27 03:16:48
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=company, name_first=user.first_name, name_last=user.last_name) profile = UserProfile.objects.create(user