signals

PHP: Am I mixing up event-driven programming with signals-aware interfaces (Signal and Slots / Observer Pattern)?

▼魔方 西西 提交于 2019-12-03 03:12:13
问题 I've seen a lot of people saying that Symfony2, Zend Framework 2 and others are event-driven. On the desktop world, by event-driven programming I understand that the application will notify its observers whenever its state changes. Since PHP applications are state-less there's no way to do such thing. I.E. Having observers tied to the view observing changes while the user uses the interface. Instead it needs a new request process in order to update the view. So, it's not an event but a whole

How to intercept EXC_BAD_INSTRUCTION when unwrapping Nil

无人久伴 提交于 2019-12-03 03:11:31
I am building some rudimentary crash logging system based on this blog post ( Yes , I am aware of PLCRashReporter, and No , I can't use it and need to roll my own, however limited. Thank you). My code registers both an exception handler (with NSSetUncaughtExceptionHandler() ) and a signal handler for most signals: SIGQUIT SIGILL SIGTRAP SIGABRT SIGEMT SIGFPE SIGBUS SIGSEGV SIGSYS SIGPIPE SIGALRM SIGXCPU SIGXFSZ It seems to work fine with basic Objective-C stuff such as "unrecognized selector sent to instance...", etc. Next, I tried it with the following Swift code: var empty:String! = nil let

multi-threaded signal handling

浪尽此生 提交于 2019-12-03 02:51:33
In unix, If a multi-threaded process was sent a signal, which thread will be the one to execute the handling function? if it is a multi-cpu machine, more than 1 thread is running at the same time. which thread will be the on to run the signal handling function? Jonathan According to man 7 signal , all threads in the process share the same signal handler, and if a signal is delivered to a process with multiple threads that have not blocked the signal, one of them is arbitrarily chosen to receive it. Having a multi-CPU machine will not change these semantics. 来源: https://stackoverflow.com

Set and Oldset in sigprocmask()

◇◆丶佛笑我妖孽 提交于 2019-12-03 02:44:52
问题 I haven't completely understood, how to use sigprocmask() . Particularly, how the set and oldset and its syntax work and how to use them. int sigprocmask(int how, const sigset_t *set, sigset_t *oldset); Please explain with an example, to block, say SIGUSR1 for a few seconds and then unblock and handle it. ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ 回答1: The idea is that you provide a mask in set , effectively a list of signals. The how argument says what you should do with the mask in set . You can either

Who uses POSIX realtime signals and why?

柔情痞子 提交于 2019-12-03 02:20:08
I am not being flip I really don't get it. I just read a whole bunch of material on them and I can't figure out the use case. I am not talking talking so much about the API for which the advantages over things like signal() are clear enough. Rather it seems RT signals are meant to be user space generated but to what end? The only use seems to be a primitive IPC but everything points to them being a lousy form of IPC (e.g. awkward, limited information, not particularly efficient, etc). So where and how are they used? First of all, note that Ben's answer is correct. As far as I can tell, the

Interrupting blocked read

不想你离开。 提交于 2019-12-03 02:07:46
My program goes through a loop like this: ... while(1){ read(sockfd,buf,sizeof(buf)); ... } The read function blocks when it is waiting for input, which happens to be from a socket. I want to handle SIGINT and basically tell it to stop the read function if it is reading and then call an arbitrary function. What is the best way to do this? From read(2) : EINTR The call was interrupted by a signal before any data was read; see signal(7). If you amend your code to look more like: cont = 1; while (1 && cont) { ret = read(sockfd, buf, sizeof(buf)); if (ret < 0 && errno == EINTR) cont = arbitrary

Erlang Linux signal handling

丶灬走出姿态 提交于 2019-12-03 01:57:24
Is it possible to trap Linux signals (e.g. SIGUSR1) through an handler in Erlang? (without having to resort to a driver crafted in C) (NOT A REAL ANSWER) In 2001 someone asked: Does anyone have any examples of unix signal handling in erlang. I would like to make a loadbalancer that I have written respond to sighup. At that time the answer was: There is no provision for handling signals in Erlang "itself", i.e. you will need to use a driver - or a port program of course, might actually be a better idea. Also for the driver case, the emulator has its own handler for a number of signals, and

Is fork (supposed to be) safe from signal handlers in a threaded program?

陌路散爱 提交于 2019-12-03 01:26:14
I'm really uncertain about the requirements POSIX places on the safety of fork in the presence of threads and signals. fork is listed as one of the async-signal-safe functions, but if there is a possibility that library code has registered pthread_atfork handlers which are not async-signal-safe, does this negate the safety of fork ? Does the answer depend on whether the thread in which the signal handler is running could be in the middle of using a resource that the atfork handlers need? Or said a different way, if the atfork handlers make use of synchronization resources (mutexes, etc.) but

Is there a way to list Django signals?

怎甘沉沦 提交于 2019-12-03 01:25:51
Is there a way to see which signals have been set in Django? It's not really exposed in docs but Signal is just a class that contains a list of receivers which are called on event. You can manually check this list: from django.db.models.signals import * for signal in [pre_save, pre_init, pre_delete, post_save, post_delete, post_init, post_syncdb]: # print a List of connected listeners print signal.receivers priestc There's a django app called django-debug-toolbar which adds a little toolbar at the top of all django served pages providing info related to the backend of the page's rendering,

Making sure a Python script with subprocesses dies on SIGINT

霸气de小男生 提交于 2019-12-03 01:03:06
I've got a command that I'm wrapping in script and spawning from a Python script using subprocess.Popen . I'm trying to make sure it dies if the user issues a SIGINT . I could figure out if the process was interrupted in a least two ways: A. Die if the wrapped command has a non-zero exit status (doesn't work, because script seems to always return 0) B. Do something special with SIGINT in the parent Python script rather than simply interrupting the subprocess. I've tried the following: import sys import signal import subprocess def interrupt_handler(signum, frame): print "While there is a