signals

Why only async-signal-safe functions can be called from signal handlers safely?

时光怂恿深爱的人放手 提交于 2019-12-19 18:13:08
问题 I am still a little confused as to why exactly it is unsafe to receive a signal and call a non async safe function from within that signal handler. Could someone explain the reasoning behind this and possibly try and give me some references that I can follow to read up more on this myself? In other words I am asking why it is unsafe to say call printf from within a signal handler. Is it because of intra-process issues and possible race conditions resulting from two possible calls to printf

sigaction passes SIGINT to system call, but not signal

纵然是瞬间 提交于 2019-12-19 10:04:08
问题 I have a loop handling an accept(2) call. I want to be able to perform some cleanup when a SIGINT is sent to the program. My first thought was to use the signal function. void signal_handler(int signal) { printf("Caught signal\n"); } int main() { signal(SIGINT, &signal_handler); // ... int accept_fd = accept(sock, NULL, NULL); if (accept_fd == -1) { close(sock); perror("accept"); return 1; } // ... } However, this simply prints "Caught signal" and then the program continues on. If I modify

Creating custom keyboard controls [Elm]

ⅰ亾dé卋堺 提交于 2019-12-19 09:03:13
问题 I'm trying to create custom keyboard controls for a 4 player game. Right now, the keys are predetermined like this: type Orient = { x:Int, y:Int } type GameInput = { space:Bool, delta:Time, so1:Orient, so2:Orient, so3:Orient, so4:Orient, amount:Int } gameInput : Signal GameInput gameInput = let sampledInput = sampleOn delta <| GameInput <~ Keyboard.space ~ delta ~ Keyboard.arrows ~ Keyboard.wasd ~ Keyboard.directions (toCode 'O') (toCode 'L') (toCode 'K') (toCode 'M') ~ Keyboard.directions

Django signal m2m_changed not triggered

↘锁芯ラ 提交于 2019-12-19 05:20:53
问题 I recently started to use signals in my Django project (v. 1.3) and they all work fine except that I just can't figure out why the m2m_changed signal never gets triggered on my model. The Section instance is edited by adding/deleting PageChild inline instances on an django admin form. I tried to register the callback function either way as described in the documentation, but don't get any result. Excerpt from my models.py from django.db import models from django.db.models.signals import m2m

Django signal m2m_changed not triggered

杀马特。学长 韩版系。学妹 提交于 2019-12-19 05:20:01
问题 I recently started to use signals in my Django project (v. 1.3) and they all work fine except that I just can't figure out why the m2m_changed signal never gets triggered on my model. The Section instance is edited by adding/deleting PageChild inline instances on an django admin form. I tried to register the callback function either way as described in the documentation, but don't get any result. Excerpt from my models.py from django.db import models from django.db.models.signals import m2m

How can I handle SIGINT in Erlang?

情到浓时终转凉″ 提交于 2019-12-18 19:38:12
问题 I know how to create custom signal handlers in Java, Python, Ruby, Perl, and Lisp, thanks to Google and a plethora of tutorials. I can't find online how to create handlers for SIGINT, SIGTERM, HUP, etc. in Erlang. 回答1: You can not. OS signals handled exclusively by Erlang VM. I guess OS signals can be handled in a driver but it can interfere with the VM signal handler so use it on your own risk. 回答2: I stumbled upon this: http://erlang.org/doc/man/kernel_app.html#erl_signal_server. I have not

Catching / blocking SIGINT during system call

天涯浪子 提交于 2019-12-18 16:49:25
问题 I've written a web crawler that I'd like to be able to stop via the keyboard. I don't want the program to die when I interrupt it; it needs to flush its data to disk first. I also don't want to catch KeyboardInterruptedException , because the persistent data could be in an inconsistent state. My current solution is to define a signal handler that catches SIGINT and sets a flag; each iteration of the main loop checks this flag before processing the next url. However, I've found that if the

Determine pid of terminated process

萝らか妹 提交于 2019-12-18 13:25:50
问题 I'm trying to figure out what the pid is of a process that sent the SIGCHLD signal, and I want to do this in a signal handler I created for SIGCHLD. How would I do this? I'm trying: int pid = waitpid(-1, NULL, WNOHANG); because I want to wait for any child process that is spawned. 回答1: If you use waitpid() more or less as shown, you will be told the PID of one of the child processes that has died — usually that will be the only process that has died, but if you get a flurry of them, you might

Signal handling on Windows

匆匆过客 提交于 2019-12-18 13:24:12
问题 I have a standalone PHP script, and I would handle a signal sent from Windows OS to do a graceful shutdown when a "kill signal" is issued. How can I do that on Windows? 回答1: While the only other answer here is succinct and accurate, it lacks detail on why there isn't signal support on Windows. First off, signals are a rather limited and outdated way of communicating with a process. There are many more richer ways to inform a process that it needs to drop what it is doing and do something else

How to do a cleanup after SIGKILL?

冷暖自知 提交于 2019-12-18 13:16:09
问题 I'm working on a program which uses shared memory. Multiple instances of said program will either connect to an existing one or create it anew, and give it back to OS when there are no other processes or just detach it and terminate. I thought of using a simple counter to keep track of how many processes use it. I'm using atexit() function to do the cleanup, however, afaik, upon receiving SIGKILL signal, processes won't do any cleanup, so if any of those processes don't terminate normally, I