signals

How to avoid the interruption of sleep calls due to a signal in Linux?

吃可爱长大的小学妹 提交于 2019-12-10 03:24:26
问题 I'm using a real time signal in Linux to be notified of the arrival of new data in a serial port. Unfortunately this causes sleep calls to be interrupted when there is signal. Does anybody know of a way to avoid this behavior? I tried using a regular signal (SIGUSR1) but I keep getting the same behavior. 回答1: From the nanosleep manpage: nanosleep delays the execution of the program for at least the time specified in *req. The function can return earlier if a signal has been delivered to the

how to handle os.system sigkill signal inside python?

走远了吗. 提交于 2019-12-10 02:56:34
问题 I have a python script where I call a lengthy process from the operating system. After a long while, the process that I call gets terminated by the system by SIGKILL signal. Is it possible to handle this from inside Python like in a try and catch situation? What method should I use to solve this issue. It is very important that this process keeps on running as long as possible without any interruptions. 回答1: There is no way to handle SIGKILL The signals SIGKILL and SIGSTOP cannot be caught,

Kill bash script foreground children when a signal comes

南笙酒味 提交于 2019-12-10 01:24:04
问题 I am wrapping a fastcgi app in a bash script like this: #!/bin/bash # stuff ./fastcgi_bin # stuff As bash only executes traps for signals when the foreground script ends I can't just kill -TERM scriptpid because the fastcgi app will be kept alive. I've tried sending the binary to the background: #!/bin/bash # stuff ./fastcgi_bin & PID=$! trap "kill $PID" TERM # stuff But if I do it like this, apparently the stdin and stdout aren't properly redirected because it does not connect with lighttpds

The invocation of signal handler and atexit handler in Python

大憨熊 提交于 2019-12-09 23:36:03
问题 I have a piece of Python code as below: import sys import signal import atexit def release(): print "Release resources..." def sigHandler(signo, frame): release() sys.exit(0) if __name__ == "__main__": signal.signal(signal.SIGTERM, sigHandler) atexit.register(release) while True: pass The real code is far more complex than this snippets, but the structures are the same: i.e. main function maintains an infinite loop. I need a signal callback to release the resources occupied, like DB handle.

How to gracefully terminate an asyncio script with Ctrl-C?

隐身守侯 提交于 2019-12-09 16:14:14
问题 I've read every post I could find about how to gracefully handle a script with an asyncio event loop getting terminated with Ctrl-C, and I haven't been able to get any of them to work without printing one or more tracebacks as I do so. The answers are pretty much all over the place, and I haven't been able implement any of them into this small script: import asyncio import datetime import functools import signal async def display_date(loop): end_time = loop.time() + 5.0 while True: print

Elegant way to disconnect slot after first call

自古美人都是妖i 提交于 2019-12-09 10:31:03
问题 Inside the constructor, there is a connection: connect(&amskspace::on_board_computer_model::self(), SIGNAL(camera_status_changed(const amskspace::camera_status_t&)), this, SLOT(set_camera_status(const amskspace::camera_status_t&))); And the method: void camera_model:: set_camera_status(const amskspace::camera_status_t& status) { disconnect(&amskspace::on_board_computer_model::self(), SIGNAL(camera_status_changed(const amskspace::camera_status_t&)), this, SLOT(set_camera_status(const amskspace

Catching signals: Use a member function as signal handler

旧城冷巷雨未停 提交于 2019-12-09 10:26:26
问题 I have an object which does some work in an endless loop. The main() instantiates the object and calls the run() method. Since I don't want to use threads, I need a solution to make my object stop running. Below you see what I've come up with. struct Foo { void run() { running = 1; while (running) do_something_useful(); std::cout << "Execution stopped." << std::endl; } bool running; void catch_signal(int signal) { std::cout << "Caught signal " << signal << std::endl; if( signal == SIGTERM )

In a signal handler, how to know where the program is interrupted?

放肆的年华 提交于 2019-12-09 09:46:53
问题 On x86 (either 64-bit or 32-bit) Linux -- for example: void signal_handler(int) { // want to know where the program is interrupted ... } int main() { ... signal(SIGALRM, signal_handler); alarm(5); ... printf(...); <------- at this point, we trigger signal_handler ... } In signal_handler, how can we know we are interrupted at printf in main()? 回答1: Use sigaction with SA_SIGINFO set in sa_flags. Prototype code: #define _GNU_SOURCE 1 /* To pick up REG_RIP */ #include <stdio.h> #include <signal.h

Linux blocking signals to Python init

对着背影说爱祢 提交于 2019-12-09 09:39:46
问题 This is a follow up to my other post Installing signal handler with Python. In short, Linux blocks all signals to PID 1 (including SIGKILL) unless Init has installed a signal handler for a particular signal; as to prevent kernel panic if someone were to send a termination signal to PID1. The issue I've been having, is it would seem that the signal module in Python doesn't install signal handlers in a way the system recognises. My Python Init script was seemingly, completely ignoring all

Calling kill on a child process with SIGTERM terminates parent process, but calling it with SIGKILL keeps the parent alive

和自甴很熟 提交于 2019-12-09 05:55:45
问题 This is a continuation of How to prevent SIGINT in child process from propagating to and killing parent process? In the above question, I learned that SIGINT wasn't being bubbled up from child to parent, but rather, is issued to the entire foreground process group, meaning I needed to write a signal handler to prevent the parent from exiting when I hit CTRL + C . I tried to implement this, but here's the problem. Regarding specifically the kill syscall I invoke to terminate the child, if I