Tag Info

New answers tagged

2

If you call the binary in /etc/rc.local, notice that rc.local is called as /bin/sh -e. -e means that the script immediately exits if any untested command fails in it. You call the binary in the background and another command in the script may exit with an exit code that is not 0. That has the effect that your binary is sighup-ed. An untested command ...


0

I tried all the solutions and this was the best: ssh host "sleep 99 < <(cat; kill -INT 0)" <&1 http://stackoverflow.com/questions/3235180/starting-a-process-over-ssh-using-bash-and-then-killing-it-on-sigint/25882610#25882610


0

----- command.sh #! /bin/sh trap 'trap - EXIT; kill 0; exit' EXIT (sleep 1000;echo f) & read ans ----- on local terminal sleep 864000 | ssh -T server command.sh > foo


1

Bash does not forward signals like SIGTERM to processes it is currently waiting on. If you want to end your script by segueing into your server (allowing it to handle signals and anything else, as if you had started the server directly), you should use exec, which will replace the shell with the process being opened: #!/bin/bash echo "Doing some initial ...


1

If by "didn't work as expected" you mean you wrote a SIGTERM handler and it did not fire for SIGTERM, you've made a mistake in your code. Here's a working example: #!/bin/bash cleanup () { echo "goodbye!" exit 0 } trap 'cleanup' SIGTERM while sleep 1; do echo $BASHPID done Reacts as expected to kill -SIGTERM. You can use any ...


3

This seems to work: #!/bin/sh pressed_ctrl_c= trap "pressed_ctrl_c=1" INT while true do (trap "" INT; foo)& wait || wait if [ "$pressed_ctrl_c" ] then # echo break fi done Initialize pressed_ctrl_c to null.  This is probably not necessary in a script. trap command signum tells ...


3

You could try this sort of construct: #!/bin/bash # INTR= trap 'INTR=yes; echo "** INTR **" >&2' INT while : do ( # Protect the subshell block trap '' INT # Protected code here echo -n "The date/time is: " sleep 2 date read -t2 -p 'Continue (y/n)? ' YN || echo test n = "$YN" ...


0

I'm currently investigating a similar issue with one of our servers. The application logs show that it terminated following a signal 15 (SIGTERM). Browsing through the logs, I found that the server was rebooted at that time, which could account for the system sending a SIGTERM to all the processes.



Top 50 recent answers are included