signals

Using sigaction(), c

萝らか妹 提交于 2019-12-21 01:57:29
问题 I was doing a little reading about sigaction() (sources are from my course notes) and I'm not sure I understand this text: The signal mask is calculated and installed only for the duration of the signal handler. By default, the signal “sig” is also blocked when the signal occurs. Once an action is installed for a specific signal using sigaction, it remains installed until another action is explicitly requested. Does this mean that the default signal mask is restored after returning form the

Handling Signals in Python Threads

橙三吉。 提交于 2019-12-21 01:29:32
问题 I have a threaded application written in Python, and whenever an interrupt is received via Ctrl + C or sometimes with kill, the application will hang. A stack trace is presented from one thread, but the application remains in the foreground, and I usually have to background it with Ctrl + Z then attempt to kill it. What is the proper way of handling signals and keyboard interrupts inside of a threaded application? 回答1: If you set newthread.daemon = True before starting each thread, the

Trap signal in child background process

淺唱寂寞╮ 提交于 2019-12-20 19:41:57
问题 I am unable to trap a signal when running in a child / background process. Here is my simple bash script : #!/bin/bash echo "in child" trap "got_signal" SIGINT function got_signal { echo "trapped" exit 0 } while [ true ]; do sleep 2 done When running this and later do kill -SIGINT (pid) Everything works as expected, it prints 'trapped' and exits. Now, if I start the same script from a parent script like this : #!/bin/bash echo "starting the child" ./child.sh & Then the child does not trap the

Python cross correlation

时光毁灭记忆、已成空白 提交于 2019-12-20 15:21:10
问题 I have a pair of 1D arrays (of different lengths) like the following: data1 = [0,0,0,1,1,1,0,1,0,0,1] data2 = [0,1,1,0,1,0,0,1] I would like to get the max cross correlation of the 2 series in python. In matlab, the xcorr() function will return it OK I have tried the following 2 methods: numpy.correlate(data1, data2) signal.fftconvolve(data2, data1[::-1], mode='full') Both methods give me the same values, but the values I get from python are different from what comes out of matlab. Python

Explanation of sigsuspend needed

爷,独闯天下 提交于 2019-12-20 14:10:07
问题 I need a clarification on sigsuspend topic. I have a simplified example sigset_t mask, oldmask; sigemptyset (&mask); sigaddset (&mask, SIGRTMIN+1); sigprocmask (SIG_BLOCK, &mask, &oldmask); sigsuspend(&oldmask); sigprocmask (SIG_UNBLOCK, &mask, NULL); Here is how I understand this: sigemptyset clears a list of signals (mask) - because it is initialized with currently blocked signals (?) sigaddset adds SIGRTMIN+1 to mask sigprocmask sets all signals in mask+oldmask to be blocked sigsuspend(

How to properly wait for foreground/background processes in my own shell in C?

社会主义新天地 提交于 2019-12-20 12:41:31
问题 In this previous question I posted most of my own shell code. My next step is to implement foreground and background process execution and properly wait for them to terminate so they don't stay as "zombies". Before adding the possibility to run them in the background, all processes were running in the foreground. And for that, I simply called wait(NULL) after executing any process with execvp(). Now, I check for the '&' character as the last argument and if it's there, run the process in the

Is there a way to list Django signals?

非 Y 不嫁゛ 提交于 2019-12-20 11:21:10
问题 Is there a way to see which signals have been set in Django? 回答1: 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 回答2: There's a django app called django-debug-toolbar which adds a little toolbar

How to determine if code is running in signal-handler context?

孤街浪徒 提交于 2019-12-20 10:55:58
问题 I just found out that someone is calling - from a signal handler - a definitely not async-signal-safe function that I wrote. So, now I'm curious: how to circumvent this situation from happening again? I'd like to be able to easily determine if my code is running in signal handler context (language is C, but wouldn't the solution apply to any language?): int myfunc( void ) { if( in_signal_handler_context() ) { return(-1) } // rest of function goes here return( 0 ); } This is under Linux. Hope

Golang catch signals

╄→尐↘猪︶ㄣ 提交于 2019-12-20 09:36:18
问题 I want to implement a "process wrapper" in Go. Basically what it will do, is launch a process (lets say a node server) and monitor it (catch signals like SIGKILL, SIGTERM ...) I think the way to do is to launch the node server in a go routine using syscall.Exec : func launchCmd(path string, args []string) { err := syscall.Exec(path, args, os.Environ()) if err != nil { panic(err) } } Then I'd like to catch every possible signals generated by the command executed by syscall . I'm pretty new to

Send signals to remote process with Python

被刻印的时光 ゝ 提交于 2019-12-20 06:14:45
问题 There are two machines, where one has a script wait_for_signal.sh , and the second one has a script named controller.py . The code of each script is shown below. The purpose of the controller.py is to spawn a subprocess that calls the wait_for_signal.sh script through ssh . When the controller needs to exit it needs to send an interrupt to the remote process that runs wait_for_signal.sh . wait_for_signal.sh #!/bin/bash trap 'break' SIGINT trap 'break' SIGHUP echo "Start loop" while true; do