signals

What is the correct way to force an app to core dump and quit?

寵の児 提交于 2019-12-01 02:45:25
问题 I just came across some code which used the kill system call to send a SIGSEGV signal to an app. The rationale behind this was that this would force the app to core dump and quit. This seems so wrong to me, is this normal practice? 回答1: SIGQUIT is the correct signal to send to a program if you wish to produce a core dump. kill is the correct command line program to send signals (it is of course poorly named, since not all signals will kill the program). Note, you should not send random

MySQL exception handler access exception being handled

梦想与她 提交于 2019-12-01 01:54:36
问题 I'm trying to rollback on an error, but still let the client receive the error. This might actually be impossible, unless there is a way to access the error in an exception handler. It's possible to "throw" from an exception, i.e. it's possible to raise a signal: CREATE PROCEDURE p () BEGIN DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN SIGNAL SQLSTATE VALUE '99999' SET MESSAGE_TEXT = 'An error occurred'; END; DROP TABLE no_such_table; END; But this sample code from the MySQL doc looks horrible

MATLAB - Pitch Shifting an Audio Signal

风格不统一 提交于 2019-12-01 01:42:29
My group is developing a simple MATLAB Graphical User Interface (GUI) that is supposed to record audio from a microphone - plugged in or built in to the computer - and play back the signal. So far we have that completed. Our GUI also can load a sample (a .wav file, etc..) and play it back using the same "Play" pushbutton on the GUI. We have a Play, Record, Load, and Save push button. Now for the pitch-shifting of loaded or recorded samples... We know we need a peak-picking algorithm to find the fundamental frequencies of the signals. We were then thinking that we could multiply each of those

Django 1.2: How to connect pre_save signal to class method

不羁的心 提交于 2019-12-01 01:39:48
问题 I am trying to define a "before_save" method in certain classes in my django 1.2 project. I'm having trouble connecting the signal to the class method in models.py. class MyClass(models.Model): .... def before_save(self, sender, instance, *args, **kwargs): self.test_field = "It worked" I've tried putting pre_save.connect(before_save, sender='self') in 'MyClass' itself, but nothing happens. I've also tried putting it at the bottom of the models.py file: pre_save.connect(MyClass.before_save,

signal.alarm function with resolution greater than 1 second?

大城市里の小女人 提交于 2019-12-01 00:51:18
问题 I'm trying to build a python timeout exception that runs in milliseconds. The python signal.alarm function has a 1 second resolution. How would one get an equivalent function that requests a SIGALRM signal to a given process in, say milliseconds, as opposed to seconds? I've found no simple solutions as of yet. Thanks in advance for your input. 回答1: Use signal.setitimer() instead. 来源: https://stackoverflow.com/questions/3770711/signal-alarm-function-with-resolution-greater-than-1-second

How can I override the keyboard interrupt? (Python)

左心房为你撑大大i 提交于 2019-12-01 00:27:04
问题 Is there anyway I can make my script execute one of my functions when Ctrl+c is hit when the script is running? 回答1: Take a look at signal handlers. CTRL-C corresponds to SIGINT (signal #2 on posix systems). Example: #!/usr/bin/env python import signal import sys def signal_handler(signal, frame): print 'You pressed Ctrl+C - or killed me with -2' sys.exit(0) signal.signal(signal.SIGINT, signal_handler) print 'Press Ctrl+C' signal.pause() 回答2: Sure. try: # Your normal block of code except

Linux: handling a segmentation fault and getting a core dump

眉间皱痕 提交于 2019-12-01 00:03:25
问题 When my application crashes with a segmentation fault I'd like to get a core dump from the system. I do that by configuring before hand ulimit -c unlimited I would also like to have an indication in my application logs that a segmentation fault has occured. I do that by using sigaction(). If I do that however, the signal does not reach its default handling and a core dump is not saved. How can I have both the system core dump an a log line from my own signal handler at the same time? 回答1:

How does processes synchronization using signals work?

耗尽温柔 提交于 2019-11-30 23:58:43
I've recently finished Section 10 (Signals) of "Advanced Programming in the Unix Environment" (3rd edition) and I've come across a piece of code I don't entirely understand: #include "apue.h" static volatile sig_atomic_t sigflag; /* set nonzero by sig handler */ static sigset_t newmask, oldmask, zeromask; static void sig_usr(int signo) /* one signal handler for SIGUSR1 and SIGUSR2 */ { sigflag = 1; } void TELL_WAIT(void) { if (signal(SIGUSR1, sig_usr) == SIG_ERR) err_sys("signal(SIGUSR1) error"); if (signal(SIGUSR2, sig_usr) == SIG_ERR) err_sys("signal(SIGUSR2) error"); sigemptyset(&zeromask);

Howto kill a thread in Haskell

偶尔善良 提交于 2019-11-30 23:09:00
问题 Using Control.Concurrent and forkIO there are some cases that will leave the thread in a blocked state (this is especially frequent under windows with networking) so even if one try to use killThread the exception is never raised in the thread. Is there any other way to force a thread to die? My attempt to terminate the whole application with exitFailure from a helper thread don't have any effect under these conditions. The Glorious Glasgow Haskell Compilation System, version 6.12.1 HP 2010.1

Guaranteeing mutex safety with async signals

孤街浪徒 提交于 2019-11-30 22:18:10
First, I am aware that the mutexes are not considered async-safe normally. This question concerns the use of sigprocmask to make mutexes safe in a multithreaded program with async signals and signal handlers. I have some code conceptually like the following: struct { int a, b; } gvars; void sigfoo_handler(int signo, siginfo_t *info, void *context) { if(gvars.a == 42 || gvars.b == 13) { /* run a chained signal handler */ } } /* called from normal code */ void update_gvars(int a, int b) { gvars.a = a; gvars.b = b; } gvars is a global variable which is too large to fit in a single sig_atomic_t .