signals

Portable way to catch signals and report problem to the user

こ雲淡風輕ζ 提交于 2019-12-06 06:09:48
问题 If by some miracle a segfault occurs in our program, I want to catch the SIGSEGV and let the user (possibly a GUI client) know with a single return code that a serious problem has occurred. At the same time I would like to display information on the command line to show which signal was caught. Today our signal handler looks as follows: void catchSignal (int reason) { std :: cerr << "Caught a signal: " << reason << std::endl; exit (1); } I can hear the screams of horror with the above, as I

Stopping getline in C

夙愿已清 提交于 2019-12-06 06:06:47
Here I'm trying to get an user input with getline . Upon receiving an interrupt ^C I want it to signal getline to stop and resume with my program instead of terminating it. I tried to write a newline to stdin but apparently that doesn't work. fwrite("\n", 1, 1, stdin); So what would be a way to achieve this? Assuming your code resembles this: int main(int argc, char **argv) { //Code here (point A) getline(lineptr, size, fpt); //More code here (point B) } Include <signal.h> and bind SIGINT to a handler function f . #include <signal.h> //Declare handler for signals void signal_handler(int signum

multiple signals for one slot

雨燕双飞 提交于 2019-12-06 05:26:27
For my GUI i would like to have two pairs of buttons that scroll up and down a scrollarea. The first set of buttons should work on say scrollarea1 and the second set of buttons should work on a scrollarea2. The widgets that I put in the scrollarea are called viewport1 and viewport2. Since both both set of buttons should do the same (scrolling up and down) I thought I would make two slots called scrollUp and scrollDown that would handle the scrolling for both sets of buttons. Unfortunately I cannot make this work and need some help. I have tried the following: QPushButton up; QPushButton down;

Trapping signals in Python

你。 提交于 2019-12-06 05:09:05
According to the documentation : There is no way to “block” signals temporarily from critical sections (since this is not supported by all Unix flavors). What stops me using signal.signal(signum,SIG_IGN) to block it, then adding the signal back? What stops you is that, if the signal actually arrives while SIG_IGN is in place, then it will be ignored and thrown away. When you add the signal back later, it's too late because it's gone and you'll never get to learn that it happened. Thus, you will have "ignored" (= thrown away) the signal rather than "blocked" it (= kept it for handling at the

malloc inside linux signal handler cause deadlock

十年热恋 提交于 2019-12-06 04:34:36
问题 First of all sorry for calling malloc inside signal handler :).I too understand we should not do any time consuming task/this kind of nasty stuff inside signal handler. But i am curious to know the reason why it is crashed ? #0 0x00006e3ff2b60dce in _lll_lock_wait_private () from /lib64/libc.so.6 #1 0x00006e3ff2aec138 in _L_lock_9164 () from /lib64/libc.so.6 #2 0x00006e3ff2ae9a32 in malloc () from /lib64/libc.so.6 #3 0x00006e3ff1f691ad in ?? () from .. i got similar core reported in https:/

How do I force a SIGILL to be sent to my program?

…衆ロ難τιáo~ 提交于 2019-12-06 04:07:49
问题 I'm try to do some nasty hacky things with dynamically generated code, and I want the OS to send me a SIGILL when it reaches an unknown opcode. This would let me add a layer of meta-information about my program and so on. However, for my little test program, it seems the OS is not sending the SIGILL, but rather sends either a SIGBUS, or a SIGSEGV. I'm guessing this means that the page in which the memory is located has an NX bit set on it. Any tips on how to make memory executable? For

Why doesn't child process continue running after receiving signal?

风流意气都作罢 提交于 2019-12-06 03:51:10
The following is my code. Parent forks a child. Child pause until parent sends a signal to it, then it continues running. My question is why doesn't child process continue running after parent sending signal to him. Did I miss or misunderstand something? #include<stdio.h> #include<unistd.h> #include<signal.h> void sigusr1( int pidno ) { printf("Catched\n"); } int main() { pid_t pid; signal( SIGUSR1, sigusr1 ); if( (pid = fork()) == 0 ){ pause(); printf("Child\n"); } kill( pid , SIGUSR1 ); //parent sends signal to child pause(); } Here's what happens in the parent: Fork a child. Send SIGUSR1 to

where to put django signal receiver code, spread them over multiple files?

一个人想着一个人 提交于 2019-12-06 03:33:37
问题 I've put my signal receiver code in the respective model file. However, signal receivers keep growing and I'd like to separate them over multiple files. I haven't seen discussion on where to put signal receiver codes. (makes me suspect that I'm not supposed to make many signal receivers maybe?) 回答1: See the docs: https://docs.djangoproject.com/en/1.8/topics/signals/#connecting-receiver-functions it's common to put them in a separate signals.py file, perhaps one per module in your project, but

kill signal example

孤人 提交于 2019-12-06 03:07:00
问题 I'm trying this example that I took from: http://www.cs.cf.ac.uk/Dave/C/node24.html: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <signal.h> void sighup(); /* routines child will call upon sigtrap */ void sigint(); void sigquit(); main() { int pid; /* get child process */ if ((pid = fork()) < 0) { perror("fork"); exit(1); } if (pid == 0) { /* child */ printf("\nI am the new child!\n\n"); signal(SIGHUP,sighup); /* set function calls */ signal(SIGINT,sigint); signal

libsigsegv and responding to a stack overflow

天大地大妈咪最大 提交于 2019-12-06 03:06:58
问题 We are attempting to test student code, and in an effort to automate the process, we'd like to detect if a student's code overflows the stack. I've met with some success using the libsigsegv library and its corresponding stackoverflow_install_handler. It works brilliantly, until the student's code blows the stack twice. For example, here's some sample output: [# ~]$ ledit ./interpreter -> (use solution) -> (fun 1 2) *** Stack overflow detected *** -> (fun 1 2) Signal -10 [# ~] The initial " *