signals

Getting fault address that generated a UNIX signal

倖福魔咒の 提交于 2019-11-30 09:11:31
问题 I am interested in a signal handler which can identify the address of the instruction which caused the problem. I know about siginfo_t and __builtin_return_address and neither seem to work: #include <iostream> #include <signal.h> void handler (int, siginfo_t *, void *); int main () { begin: std :: cerr << &&begin << " ~ " << &&before << " ~ " << &&after << "\n"; struct sigaction s; s .sa_flags = SA_SIGINFO; sigemptyset (& s .sa_mask); s .sa_sigaction = handler; sigaction (SIGSEGV, &s, NULL);

How to do a cleanup after SIGKILL?

房东的猫 提交于 2019-11-30 09:04:40
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 might never be able to clean the memory. Is there a way to specify what to do even after a SIGKILL

Why is post_save being raised twice during the save of a Django model?

北慕城南 提交于 2019-11-30 08:27:05
I am attaching a method to the post_save signal of my Django model. This way I can clear some cached items whenever the model is modified. The problem I am having is that the signal is being triggered twice when the model is saved. It doesn't necessarily hurt anything (the code will just gracefully error out) but it can't be right. A quick example, just printing the model to the console (using the dev server): from blog.models import Post from django.db.models import signals def purge_cache(sender, **kwargs): print 'Purging %s' % sender signals.post_save.connect(purge_cache, sender=Post) This

How to stop python from propagating signals to subprocesses?

和自甴很熟 提交于 2019-11-30 07:58:05
问题 I'm using python to manage some simulations. I build the parameters and run the program using: pipe = open('/dev/null', 'w') pid = subprocess.Popen(shlex.split(command), stdout=pipe, stderr=pipe) My code handles different signal. Ctrl+C will stop the simulation, ask if I want to save, and exit gracefully. I have other signal handlers (to force data output for example). What I want is to send a signal (SIGINT, Ctrl+C) to my python script which will ask the user which signal he wants to send to

Why does using threading.Event result in SIGTERM not being caught?

别说谁变了你拦得住时间么 提交于 2019-11-30 07:56:00
问题 I have a threaded Python daemon. Like any good daemon, it wants to launch all of its worker threads, then wait around until it's told to terminate. The normal signal for termination is SIGTERM , and in most languages I'd hold to terminate by waiting on an event or mutex, so using threading.Event made sense to me. The problem is that Python's Event object and Unix signals don't appear to be playing well together. This works as expected, terminating on SIGTERM : import signal import time RUN =

How, in Perl 5, can I get the pid of the process who sent me a signal?

走远了吗. 提交于 2019-11-30 07:51:18
In C, I can say #include <stdio.h> #include <unistd.h> #include <signal.h> int continue_running = 1; void handler(int signal, siginfo_t* info, void* data) { printf("got signal %d from process %d running as user %d\n", signal, info->si_pid, info->si_uid); continue_running = 0; } int main(int argc, char** argv) { struct sigaction sa; sigset_t mask; sigemptyset(&mask); sa.sa_sigaction = &handler; sa.sa_mask = mask; sa.sa_flags = SA_SIGINFO; sigaction(SIGTERM, &sa, NULL); printf("pid is %d\n", getpid()); while (continue_running) { sleep(1); }; return 0; } This prints out something like pid is

Is there any way to create a user defined signal in Linux?

人走茶凉 提交于 2019-11-30 07:13:36
问题 Is there any way to create a user defined signals in Linux? My signal (signal number) should not match any of the existing signal numbers. In other words, i want to create my own unique signal, which will be registered and caught by my handler. Is it possible? If yes, how? Thanks in advance. 回答1: You can't add or register your own SIGWHATEVER. See sigset_t , it is fixed size. See valid_signal() beartraps. 回答2: SIGRTMIN through SIGRTMAX (these are not normally constants but macros which expand

how to use “sigaltstack” in signal handler program?

久未见 提交于 2019-11-30 07:10:42
did anyone who knows how to use the sigaltstack in a real signal handler program,a simple but complete code may be great help to me! thank you in advance! Here is a minimal sample program that uses sigaltstack to catch infinite recursion. If you comment out the sigaltstack call or SA_ONSTACK flag, the signal handler will not be able to run because it has no stack left and the program will just crash. #define _XOPEN_SOURCE 700 #include <signal.h> #include <unistd.h> void handler(int sig) { write(2, "stack overflow\n", 15); _exit(1); } unsigned infinite_recursion(unsigned x) { return infinite

What does SEGV_ACCERR mean?

别说谁变了你拦得住时间么 提交于 2019-11-30 06:23:20
I am examining a few crashes that all have the signal SIGSEGV with the reason SEGV_ACCERR. After searching for SEGV_ACCERR, the closest thing I have found to a human readable explanation is: Invalid Permissions for object What does this mean in a more general sense? When would a SEGV_ACCERR arise? Is there more specific documentation on this reason? This is an error that I have mostly seen on 64 bit iOS devices and can happen if multiple threads read and change a variable under ARC. For example, I fixed a crash today where multiple background threads were reading and using a static NSDate and

How can I send a signal from a python program?

余生颓废 提交于 2019-11-30 06:21:40
I have this code which listens to USR1 signals import signal import os import time def receive_signal(signum, stack): print 'Received:', signum signal.signal(signal.SIGUSR1, receive_signal) signal.signal(signal.SIGUSR2, receive_signal) print 'My PID is:', os.getpid() while True: print 'Waiting...' time.sleep(3) This works when I send signals with kill -USR1 pid But how can I send the same signal from within the above python script so that after 10 seconds it automatically sends USR1 and also receives it , without me having to open two terminals to check it? moomima You can use os.kill() : os