signals

How can I send a signal from a python program?

假装没事ソ 提交于 2019-12-18 12:12:45
问题 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

How to trap a SIGNAL in a java application initialized using a bash script

∥☆過路亽.° 提交于 2019-12-18 11:56:58
问题 I am catching an INT signal in java using the following code: Signal.handle(new Signal("INT"), new SignalHandler () { public void handle(Signal sig) { log.warn("Received SIGINT signal. Will teardown."); task.tearDown(); // Force exit anyway System.exit(1); } }); When I am using java -jar file.jar to start my application I can catch the signal sent with with kill -INT PID . If I call java -jar file.jar & (jvm runs in the background), I can't catch the signal sent with kill -INT . Any ideas?

Unix pthreads and signals: per thread signal handlers

拟墨画扇 提交于 2019-12-18 11:47:50
问题 I'm having trouble getting threads to catch the correct signals. For example, I first start a main thread (tid 1). Then, it sets a signal handler for SIGUSR1 to function1(), using signal(2) . The main thread creates a new thread, with tid 2. In thread 2, I register a signal handler for SIGUSR1 to function2() using signal(2) . Thread 1 then creates a thread 3 (tid 3). From thread 3, I use pthread_kill(1, SIGUSR1) to send a signal to thread 1. However, function2() gets called, not function1() .

Linux C/C++ Timer signal handler in userspace

坚强是说给别人听的谎言 提交于 2019-12-18 08:47:17
问题 I need a function(eg signal handler) in C/C++ linux that gets activated every 'n' milliseconds. How do I setup signals etc...to register to timer events at the millisecond resolution. Accuracy is not super critical, but need within hundred ms or so. I am new to linux and I really don't know where to start. 回答1: setitimer(2) is a good start, but do you really want to go asynchronous with signals? Otherwise, you could have a main loop with select(2) or poll(2) and an appropiate timeout. 回答2: A

Windows console application - signal for closing event

♀尐吖头ヾ 提交于 2019-12-18 06:56:29
问题 In windows console application, one can catch pressing ctrl+c by using: #include <stdio.h> #include <signal.h> void SigInt_Handler(int n_signal) { printf("interrupted\n"); } int main(int n_arg_num, const char **p_arg_list) { signal(SIGINT, &SigInt_Handler); getchar(); // wait for user intervention } This works well, except it does not work at all if the user presses the cross × that closes the console window. Is there any signal for that? The reason I need this is I have this CUDA application

Django signals not working properly

社会主义新天地 提交于 2019-12-18 06:22:22
问题 I'm trying to setup a signal so that when a valid form is saved, a function is ran to carry out a related task. My app structure is as follows; - events - helpers - __init__.py - status.py - models - signals - __init__.py - event.py - __init__.py - event.py - status.py - views - __init__.py - event.py I believe signals need to be imported as early as possible, before models, so at the top of models/__init__.py I've got from .signals import * . # views/event.py class AddEventView(CreateView):

C SIGSEGV Handler & Mprotect

戏子无情 提交于 2019-12-18 05:09:12
问题 I'm constructing a program which uses mprotect() to restrict a block of memory from accessing. When the memory is requested, a SIGSEGV is thrown which I listen for using a signal() call. Once the SIGSEGV has been detected, I need to somehow access the pointer to the memory that was requested (that threw the fault) and the size of the segment requested. Is this possible? void fifoSigHandler(){ // Needs to only remove protection from requested block of virtual memory mprotect(fifoVm,(size_t

Which thread handles the signal?

若如初见. 提交于 2019-12-18 01:13:13
问题 I have 2 threads(thread1 and thread2). And I have signal disposition for SIGINT . Whenever SIGINT occurs thread 2 should handle the signal. For that I wrote below program void sig_hand(int no) //signal handler { printf("handler executing...\n"); getchar(); } void* thread1(void *arg1) //thread1 { while(1) { printf("thread1 active\n"); sleep(1); } } void * thread2(void * arg2) //thread2 { signal(2, sig_hand); while(1) { printf("thread2 active\n"); sleep(3); } } int main() { pthread_t t1;

How do unix signals work?

醉酒当歌 提交于 2019-12-17 23:04:32
问题 How do signals work in unix? I went through W.R. Stevens but was unable to understand. Please help me. 回答1: The explanation below is not exact, and several aspects of how this works differ between different systems (and maybe even the same OS on different hardware for some portions), but I think that it is generally good enough for you to satisfy your curiosity enough to use them. Most people start using signals in programming without even this level of understanding, but before I got

recv() is not interrupted by a signal in multithreaded environment

孤街浪徒 提交于 2019-12-17 22:43:15
问题 I have a thread that sits in a blocking recv() loop and I want to terminate (assume this can't be changed to select() or any other asynchronous approach). I also have a signal handler that catches SIGINT and theoretically it should make recv() return with error and errno set to EINTR . But it doesn't, which I assume has something to do with the fact that the application is multi-threaded. There is also another thread, which is meanwhile waiting on a pthread_join() call. What's happening here?