signals

Trapping signals in a Swift command line application

僤鯓⒐⒋嵵緔 提交于 2019-11-26 14:37:43
问题 How to capture different signals such as SIGINT and SIGTERM in Swift correctly? For example, when people stop my script by pressing Control - C , I want to do some cleanup before terminating it. 回答1: Dispatch Sources can be used to monitor UNIX signals. Here is a simple example, a Swift 3 translation of the C code in the "Monitoring Signals" section from the Concurrency Programming Guide. import Dispatch // or Foundation signal(SIGINT, SIG_IGN) // // Make sure the signal does not terminate

Does linux allow any system call to be made from signal handlers?

谁都会走 提交于 2019-11-26 14:37:22
问题 My understanding is that, in general, the behavior is undefined if you call a non-async signal safe function from a signal handler, but I've heard that linux allows you to call any system call safely. Is this true? Also, the only portable behavior for a SIGSEGV handler is to abort or exit, but I understand linux will actually resume execution if you return, true? 回答1: I would believe that any real system call can be called from a signal handler. A true syscall has a number in <asm/unistd.h>

POSIX threads and signals

落爺英雄遲暮 提交于 2019-11-26 14:08:39
I've been trying to understand the intricacies of how POSIX threads and POSIX signals interact. In particular, I'm interested in: What's the best way to control which thread a signal is delivered to (assuming it isn't fatal in the first place)? What is the best way to tell another thread (that might actually be busy) that the signal has arrived? (I already know that it's a bad idea to be using pthread condition variables from a signal handler.) How can I safely handle passing the information that a signal has occurred to other threads? Does this need to happen in the signal handler? (I do not

signal queuing in C

99封情书 提交于 2019-11-26 13:45:53
问题 I have a simple program under Linux which sends SIGUSR1 signal to its child process in a cycle. But when I send e.g. 10 signals, sometimes happens, that the child received only 3 of them. Last sent signal is always SIGUSR2 and that is received every time. Are the signals queuing, or when process didn't process the previous, it is simply overwritten? Is there a way I can send signals in a queue? 回答1: What happens is the following: First signal received, namely SIGUSR1, handler is called and is

Simple Signals - C programming and alarm function

那年仲夏 提交于 2019-11-26 13:03:40
问题 #include <stdio.h> #include <signal.h> void ALARMhandler(int sig) { signal(SIGALRM, SIG_IGN); /* ignore this signal */ printf(\"Hello\"); signal(SIGALRM, ALARMhandler); /* reinstall the handler */ } int main(int argc, char *argv[]) { alarm(2); /* set alarm clock */ while (1) ; printf(\"All done\"); } I expect the program to print \"hello\" after 2 seconds, but instead the output is \"zsh: alarm ./a.out\" Any idea what is going on? 回答1: You're forgetting to set the alarm handler initially.

signals and slots in multilayered UI widgets

孤人 提交于 2019-11-26 12:48:37
问题 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

Debugging child process after fork (follow-fork-mode child configured)

偶尔善良 提交于 2019-11-26 12:09:09
问题 I\'m developing an application which the parent forks a child to handle certain tasks. I\'m having an issue where I\'ve configured gdb to follow-fork-mode child but after fork, after reaching a breakpoint, it sends a SIGTRAP but the child somehow terminates and send SIGCHLD to the parent. I\'ve configured signal(SIGTRAP, SIG_IGN) before fork so my understanding is that the child should inherit and ignore SIGTRAP when the breakpoint is reached but it\'s not happening. Please help me to

What does `kill -0 $pid` in a shell script do?

吃可爱长大的小学妹 提交于 2019-11-26 11:52:20
问题 Basically, what signal does \'0\' represent, because here I see SIGNAL numbers starting from 1. 回答1: sending the signal 0 to a given PID just checks if any process with the given PID is running and you have the permission to send a signal to it. For more information see the following manpages: kill(1) $ man 1 kill ... If sig is 0, then no signal is sent, but error checking is still performed. ... kill(2) $ man 2 kill ... If sig is 0, then no signal is sent, but error checking is still

How and why does QuickEdit mode in Command Prompt freeze applications?

别来无恙 提交于 2019-11-26 11:51:15
I recently ran into an issue with Command Prompt on Windows where QuickEdit mode was enabled and clicking the window was selecting text and hanging a running program. This is, apparently, known behaviour—I found a few questions related to it: Command Line Windows Hanging in RDP Windows Windows Console Application Getting Stuck How to disable QuickEdit Mode for individual scripts How is the application "paused"/"suspended"? Is the process similar to the SIGSTOP signal on *nix? (I am also interested in understanding why this functionality exists in the first place? It seems unintuitive and

How can I catch a ctrl-c event?

纵然是瞬间 提交于 2019-11-26 11:33:17
How do I catch a Ctrl + C event in C++? Gab Royer signal isn't the most reliable way as it differs in implementations. I would recommend using sigaction . Tom's code would now look like this : #include <signal.h> #include <stdlib.h> #include <stdio.h> #include <unistd.h> void my_handler(int s){ printf("Caught signal %d\n",s); exit(1); } int main(int argc,char** argv) { struct sigaction sigIntHandler; sigIntHandler.sa_handler = my_handler; sigemptyset(&sigIntHandler.sa_mask); sigIntHandler.sa_flags = 0; sigaction(SIGINT, &sigIntHandler, NULL); pause(); return 0; } Chris Smith For a Windows