signals

How do I catch a KILL or HUP or User Abort signal?

孤者浪人 提交于 2019-12-05 02:11:01
I have a script running on the background of my linux server and I would like to catch signals like reboot or anything that would kill this script and instead save any importante information before actually exiting. I think most of what I need to catch is, SIGINT, SIGTERM, SIGHUP, SIGKILL. How do catch any of these signals and have it execute an exit function otherwise keep executing whatever it was doing ? pseudo perl code: #!/usr/bin/perl use stricts; use warnings; while (true) { #my happy code is running #my happy code will sleep for a few until its breath is back to keep running. } #ops I

When did HUP stop getting sent and what can I do about it?

久未见 提交于 2019-12-05 02:08:16
Back in the day when I was young and Unix was the new thing, creating a process that did not get killed when you logged out was a challenge. We used the nohup command to protect our persistent processes from the HUP signal. If we weren't careful, our processes would get killed when we logged off, or even closed the shell we started them from. Fast forward to today and I find I am surprised that the default appears to be exactly the opposite. On both Ubuntu and Red Hat systems I find that I can put nearly any process in the background, kill the parent shell, log off, anything and it just keeps

SDL/C++ OpenGL Program, how do I stop SDL from catching SIGINT

核能气质少年 提交于 2019-12-05 02:03:09
I am using SDL for an OpenGL application, running on Linux. My problem is that SDL is catching SIGINT and ignoring it. This is a pain because I am developing through a screen session, and I can't kill the running program with CTRL-C (the program the computer is running on is connected to a projector and has no input devices). Is there a flag or something I can pass to SDL so that it does not capture SIGINT? I really just want the program to stop when it receives the signal (ie when I press ctrl-c). Ctrl-C at the console generates an SDL_QUIT event. You can watch for this event using SDL

How to reliably unlink() a Unix domain socket in Go programming language

老子叫甜甜 提交于 2019-12-05 01:58:57
I have a Go program hosting a simple HTTP service on localhost:8080 so I can connect my public nginx host to it via the proxy_pass directive, as a reverse proxy to serve part of my site's requests. This is all working great, no problems there. I want to convert the Go program to host the HTTP service on a Unix domain socket instead of a local TCP socket for improved security and to reduce the unnecessary protocol overhead of TCP. PROBLEM : The problem is that Unix domain sockets cannot be reused once they are bind() to, even after program termination. The second time (and every time after) I

Ignoring Bash pipefail for error code 141

你说的曾经没有我的故事 提交于 2019-12-05 01:44:18
Setting the bash pipefail option (via set -o pipefail ) allows the script to fail if a non-zero error is caught where there is a non-zero error in any step of a pipe. However, we are running into SIGPIPE errors (error code 141), where data is written to a pipe that no longer exists. Is there a way to set bash to ignore SIGPIPE errors, or is there an approach to writing an error handler that will handle all error status codes but, say, 0 and 141? For instance, in Python, we can add: signal.signal(signal.SIGPIPE, signal.SIG_DFL) to apply the default behavior to SIGPIPE errors: ignoring them (cf.

Forwarding SIGTERM over ssh

自作多情 提交于 2019-12-05 01:33:25
I want ssh to forward the SIGTERM signal to the remote command. ssh root@localhost /root/print-signal.py Get PID of ssh: ps aux| grep print-signal Kill the matching ssh process: kill pid-of-ssh Unfortunately only the ssh process itself gets the signal, not the remote command ( print-signal.py ). The remote command does not terminate :-( How can I make ssh "forward" the SIGTERM signal to the remote command? I think you can do the following : ssh root@localhost /root/print-signal.py **Get PID of python file running ** ps aux| grep print-signal Kill the matching ssh process: ssh root@localhost

Why does ignoring SIGTRAP not work with asm?

佐手、 提交于 2019-12-05 01:26:57
问题 I'm trying to ignore SIGTRAP. I have the following proof-of-concept code: #include <signal.h> #include <stdlib.h> int main(){ signal(SIGTRAP, SIG_IGN); write(1, "A", 1); asm("int3"); write(1, "B", 1); return 0; } When I run it, I expect to see "AB", but I see ATrace/breakpoint trap (core dumped) Why does my program terminate despite it ignoring SIGTRAP? 回答1: According to this site a blocked/ignored signal is automatically unblocked inside the kernel code when it is raised. So if the same

my power spectra are believable? a comparison between lomb-scargle and fft (scipy.signal and numpy.fft)

此生再无相见时 提交于 2019-12-05 01:24:02
问题 Could anyone kindly point out why I get very different results? There are many peaks which should not appear.In fact,there should be only one peak. I am a python newbie and all comments about my code below are welcome. The test data is here.enter link description here You can directly wget https://clbin.com/YJkwr . Its first column are the arrival times for a series of photons.A light source emits photons randomly. The total time is 55736s and there are 67398 photons. I try to detect some

celery trying shutdown worker by raising SystemExit in task_postrun signal but always hangs and the main process never exits

拟墨画扇 提交于 2019-12-05 00:30:40
问题 I'm trying to shutdown the main celery process by raisin SystemExit() in the task_postrun signal. The signal gets fired just fine, and the exception gets raised, but the worker never completely exits and just hangs there. HOW DO I MAKE THIS WORK? Am I forgetting some setting somewhere? Below is the code that I'm using for the worker (worker.py): from celery import Celery from celery import signals app = Celery('tasks', set_as_current = True, broker='amqp://guest@localhost//', backend="mongodb

Kill bash script foreground children when a signal comes

我们两清 提交于 2019-12-05 00:08:11
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 mod_fastgi, the foreground version does work. EDIT: I've been looking at the problem and this happens