signals

Trap signal in child background process

♀尐吖头ヾ 提交于 2019-12-03 05:46: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 signal anymore.... ? After changing to use SIGTERM instead of SIGINT, it seems to be working correctly

When a parent process is killed by “kill -9”, will subprocess also be killed?

橙三吉。 提交于 2019-12-03 05:46:13
问题 One of my colleague told me this morning, when he killed supervisord by "kill -9", the subprocesses of supervisord is not killed. He is quite sure about that, but I tried many times and did not find that happen. So when a parent process is killed by "kill -9", will linux ensure that it's sub-processes also been killed? 回答1: You have to make the sub processes daemonic in order to have them killed when the father is killed (or dies), otherwise they are adopted by init(1). 回答2: No, child

How to trap exit code in Bash script

爷,独闯天下 提交于 2019-12-03 05:30:37
问题 There're many exit points in my bash code. I need to do some clean up work on exit, so I used trap to add a callback for exit like this: trap "mycleanup" EXIT The problem is there're different exit codes, I need to do corresponding cleanup works. Can I get exit code in mycleanup? 回答1: I think you can use $? to get the exit code. 回答2: The accepted answer is basically correct, I just want to clarify things. The following example works well: #!/bin/bash cleanup() { rv=$? rm -rf "$tmpdir" exit

pthreads : pthread_cond_signal() from within critical section

会有一股神秘感。 提交于 2019-12-03 04:27:10
问题 I have the following piece of code in thread A, which blocks using pthread_cond_wait() pthread_mutex_lock(&my_lock); if ( false == testCondition ) pthread_cond_wait(&my_wait,&my_lock); pthread_mutex_unlock(&my_lock); I have the following piece of code in thread B, which signals thread A pthread_mutex_lock(&my_lock); testCondition = true; pthread_cond_signal(&my_wait); pthread_mutex_unlock(&my_lock); Provided there are no other threads, would it make any difference if pthread_cond_signal(&my

How to signal an application without killing it in Linux?

别说谁变了你拦得住时间么 提交于 2019-12-03 04:10:16
问题 I have a watchdog application. It watches my main app which might crash for one reason or another (I know it is bad, but this is not the point). I programmed this watchdog to accept SIGUSR1 signals to stop monitoring my application presence. I signal it with kill -SIGUSR1 `pidof myapp` This works really well. My problem comes when I try to signal an older version of the watchdog which does not have this functionality built in. In this case, the kill signal kills the watchdog (terminates the

Explain void (*signal(int signo, void *(func)(int)))(int)

时光怂恿深爱的人放手 提交于 2019-12-03 03:39:18
Please explain this type signature : void (*signal(int signo, void *(func)(int)))(int) The type signature of the signal function is a bit more clear when a typedef is used for the function pointers that are passed around: typedef void (*sighandler_t)(int); sighandler_t signal(int signo, sighandler_t func); sighandler_t is a pointer to a function that takes an int parameter and returns nothing. The signal function takes such a function pointer as its second parameter. It also returns a function pointer of that type. C declarations need to be read from the inside out. The tricky part with

how to pass qobject as argument from signal to slot in qt connect

邮差的信 提交于 2019-12-03 03:30:45
My original code passed a QStringList from the signal to the slot and then returned a QList. Everything worked fine but I needed to change both the QStringList and QList into 2 different subclassed QObjects. Since then I have been receiving errors like "synthesized method first required here" or it simply crashes without any error message. I understand that qt copies all arguments passed in a queued connection and a qobject cannot be copied. So instead of returning a qobject I thought I would create both qobjects prior to emitting the signal. Then I would pass references to each object, modify

Threading and Signals problem in PyQt

不羁的心 提交于 2019-12-03 03:27:53
I'm having some problems with communicating between Threads in PyQt. I'm using signals to communicate between two threads, a Sender and a Listener. The sender sends messages, which are expected to be received by the listener. However, no messages are receieved. Can anyone suggest what might be going wrong? I'm sure it must be something simple, but I've been looking around for hours and not found anything. Thanks in advance! from PyQt4 import QtCore,QtGui import time class Listener(QtCore.QThread): def __init__(self): super(Listener,self).__init__() def run(self): # just stay alive, waiting for

Calculate the Fourier series with the trigonometry approach

左心房为你撑大大i 提交于 2019-12-03 03:19:01
I try to implement the Fourier series function according to the following formulas: ...where... ...and... Here is my approach to the problem: import numpy as np import pylab as py # Define "x" range. x = np.linspace(0, 10, 1000) # Define "T", i.e functions' period. T = 2 L = T / 2 # "f(x)" function definition. def f(x): return np.sin(np.pi * 1000 * x) # "a" coefficient calculation. def a(n, L, accuracy = 1000): a, b = -L, L dx = (b - a) / accuracy integration = 0 for i in np.linspace(a, b, accuracy): x = a + i * dx integration += f(x) * np.cos((n * np.pi * x) / L) integration *= dx return (1 /

Converting floating point exceptions into C++ exceptions

最后都变了- 提交于 2019-12-03 03:18:50
Is it possible to convert floating point exceptions (signals) into C++ exceptions on x86 Linux? This is for debugging purposes, so nonportability and imperfection is okay (e.g., if it isn't 100% guaranteed that all destructors are called). jwfearn If your C++ standard library implementation supports the TR1 functions fetestexcept , feraiseexcept and feclearexcept (mine doesn't yet so I can't test this) you can detect five kinds of floating point errors and then you can throw whatever exceptions you want. See here for a description of these functions. I also recommend section 12.3, "Managing