signal-handling

What's the difference between SIGSTOP and SIGTSTP?

时间秒杀一切 提交于 2019-11-27 06:17:35
That's it. Just wondering about the difference between SIGSTOP and SIGTSTP. jlliagre Both signals are designed to suspend a process which will be eventually resumed with SIGCONT . The main differences between them are: SIGSTOP is a signal sent programmatically (eg: kill -STOP pid ) while SIGTSTP (for sig nal - t erminal stop ) may also be sent through the tty driver by a user typing on a keyboard, usually Control - Z . SIGSTOP cannot be ignored. SIGTSTP might be. /usr/include/x86_64-linux-gnu/bits/signum.h #define SIGSTOP 19 /* Stop, unblockable (POSIX). */ #define SIGTSTP 20 /* Keyboard stop

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

Python - Trap all signals

不问归期 提交于 2019-11-27 04:23:32
In python 2.6 under Linux, I can use the following to handle a TERM signal: import signal def handleSigTERM(): shutdown() signal.signal(signal.SIGTERM, handleSigTERM) Is there any way to setup a handler for all signals received by the process, other than just setting them up one-at-a-time? You could just loop through the signals in the signal module and set them up. for i in [x for x in dir(signal) if x.startswith("SIG")]: try: signum = getattr(signal,i) signal.signal(signum,sighandler) except (OSError, RuntimeError) as m: #OSError for Python3, RuntimeError for 2 print ("Skipping {}".format(i)

Providing/passing argument to signal handler

三世轮回 提交于 2019-11-27 00:20:18
问题 Can I provide/pass any arguments to signal handler? /* Signal handling */ struct sigaction act; act.sa_handler = signal_handler; /* some more settings */ Now, handler looks like this: void signal_handler(int signo) { /* some code */ } If I want to do something special i.e. delete temp files, can I provide those files as an argument to this handler? Edit 0: Thanks for the answers. We generally avoid/discourage use of global variables. And in this case, If you have a huge program, things can go

python: windows equivalent of SIGALRM

江枫思渺然 提交于 2019-11-26 23:11:31
I have this decorator: def timed_out(timeout): def decorate(f): if not hasattr(signal, "SIGALRM"): return f def handler(signum, frame): raise TimedOutExc() @functools.wraps(f) def new_f(*args, **kwargs): old = signal.signal(signal.SIGALRM, handler) signal.alarm(timeout) try: result = f(*args, **kwargs) finally: signal.signal(signal.SIGALRM, old) signal.alarm(0) return result new_f.func_name = f.func_name return new_f return decorate The code only does anything on linux, though, as on windows, there is no SIGALRM . What would be the simplest way to have this code work in Windows as well? It's

signal handler function in multithreaded environment

 ̄綄美尐妖づ 提交于 2019-11-26 20:18:00
问题 In my multithreaded GUI application I have the following signal handling code. I want to improve this code so that it will be correct and threading safe but there are some things I don't fully understand in signal handling: is signal handled at the process or thread level (can I have thread-specific signal handlers) ? in which thread context is signal_handler function executed ? is it possible to send many SIGTERM signals in a short time ? does it make sense to use a mutex to prevent parallel

What's the difference between SIGSTOP and SIGTSTP?

一笑奈何 提交于 2019-11-26 18:53:08
问题 That's it. Just wondering about the difference between SIGSTOP and SIGTSTP. 回答1: Both signals are designed to suspend a process which will be eventually resumed with SIGCONT . The main differences between them are: SIGSTOP is a signal sent programmatically (eg: kill -STOP pid ) while SIGTSTP (for sig nal - t erminal stop ) may also be sent through the tty driver by a user typing on a keyboard, usually Control - Z . SIGSTOP cannot be ignored. SIGTSTP might be. 回答2: /usr/include/x86_64-linux

Is it possible to use signal inside a C++ class?

别来无恙 提交于 2019-11-26 15:37:50
问题 I am doing something like this: #include <signal.h> class myClass { public: void myFunction () { signal(SIGIO,myHandler); } void myHandler (int signum) { /** * Handling code */ } } I am working on Ubuntu, using gcc. But it won't compile. It is complaining with: error: the argument with type void (MyClass::)(int) doesn't agree with void (*) (int) Any clues? Or maybe it is just that I cannot use a signal inside classes? Are signals only allowed in C? The error message is an approximate

python: windows equivalent of SIGALRM

不打扰是莪最后的温柔 提交于 2019-11-26 08:32:02
问题 I have this decorator: def timed_out(timeout): def decorate(f): if not hasattr(signal, \"SIGALRM\"): return f def handler(signum, frame): raise TimedOutExc() @functools.wraps(f) def new_f(*args, **kwargs): old = signal.signal(signal.SIGALRM, handler) signal.alarm(timeout) try: result = f(*args, **kwargs) finally: signal.signal(signal.SIGALRM, old) signal.alarm(0) return result new_f.func_name = f.func_name return new_f return decorate The code only does anything on linux, though, as on

Segmentation fault handling

独自空忆成欢 提交于 2019-11-26 07:36:39
问题 I have an application which I use to catch any segmentation fault or ctrl-c. Using the below code, I am able to catch the segmentation fault but the handler is being called again and again. How can I stop them. For your information, I don\'t want to exit my application. I just can take care to free all the corrupted buffers. Is it possible? void SignalInit(void ) { struct sigaction sigIntHandler; sigIntHandler.sa_handler = mysighandler; sigemptyset(&sigIntHandler.sa_mask); sigIntHandler.sa