Signal queuing in C

What happens is the following: First signal received, namely SIGUSR1, handler is called and is running Second signal received, since handler from nr1 is still running, the signal nr2 gets pending and blocked. Third signal received, since handler from nr1 is still running, the signal 3 gets discarded. Fourth, fifth…etc signal of the same type … Read more

Which thread handles the signal?

If you send a signal to a process, which thread in the process will handle this signal is undetermined. According to pthread(7): POSIX.1 also requires that threads share a range of other attributes (i.e., these attributes are process-wide rather than per-thread): … – signal dispositions … POSIX.1 distinguishes the notions of signals that are directed … Read more

Throwing an exception from within a signal handler

Signals are totally different than C++ exceptions. You can’t use a C++ try/catch block to handle a signal. Specifically, signals are a POSIX concept, not a C++ language concept. Signals are delivered asynchronously to your application by the kernel, whereas C++ exceptions are synchronous events defined by the C++ standard. You are quite limited in … Read more

Kill or terminate subprocess when timeout?

You could do something like this: import subprocess as sub import threading class RunCmd(threading.Thread): def __init__(self, cmd, timeout): threading.Thread.__init__(self) self.cmd = cmd self.timeout = timeout def run(self): self.p = sub.Popen(self.cmd) self.p.wait() def Run(self): self.start() self.join(self.timeout) if self.is_alive(): self.p.terminate() #use self.p.kill() if process needs a kill -9 self.join() RunCmd([“./someProg”, “arg1”], 60).Run() The idea is that you … Read more