What signal is sent when you close a bash terminal to the programs it was runningWhy does closing terminal emulator window terminate a bash process with SIGHUP trap changed not to terminate?Control which process gets cancelled by Ctrl+CProgram is not launched in function that is called by a signal trapCatching a LXDE Logout with bashsigint not being propagated to background child processWays to make a process survive its parent shell's exiting?What terminal related signals are sent to the child processes of the shell directly and what signals indirectly via the shell process?trapping HUP/SIGHUP is not working in bash scriptProcess continues to run after receiving uncaught SIGINT (Ctrl-C from terminal)Process started by script does not receive SIGINTWhy does closing terminal emulator window terminate a bash process with SIGHUP trap changed not to terminate?
How does strength of boric acid solution increase in presence of salicylic acid?
Is it important to consider tone, melody, and musical form while writing a song?
Is it unprofessional to ask if a job posting on GlassDoor is real?
Why do I get two different answers for this counting problem?
What are the differences between the usage of 'it' and 'they'?
Theorems that impeded progress
Do I have a twin with permutated remainders?
Which models of the Boeing 737 are still in production?
How is it possible to have an ability score that is less than 3?
What are these boxed doors outside store fronts in New York?
Why doesn't Newton's third law mean a person bounces back to where they started when they hit the ground?
How is the claim "I am in New York only if I am in America" the same as "If I am in New York, then I am in America?
Arthur Somervell: 1000 Exercises - Meaning of this notation
What is the word for reserving something for yourself before others do?
What do you call a Matrix-like slowdown and camera movement effect?
To string or not to string
The use of multiple foreign keys on same column in SQL Server
Why, historically, did Gödel think CH was false?
How could an uplifted falcon's brain work?
TGV timetables / schedules?
Why do falling prices hurt debtors?
Test whether all array elements are factors of a number
Email Account under attack (really) - anything I can do?
Why can't I see bouncing of a switch on an oscilloscope?
What signal is sent when you close a bash terminal to the programs it was running
Why does closing terminal emulator window terminate a bash process with SIGHUP trap changed not to terminate?Control which process gets cancelled by Ctrl+CProgram is not launched in function that is called by a signal trapCatching a LXDE Logout with bashsigint not being propagated to background child processWays to make a process survive its parent shell's exiting?What terminal related signals are sent to the child processes of the shell directly and what signals indirectly via the shell process?trapping HUP/SIGHUP is not working in bash scriptProcess continues to run after receiving uncaught SIGINT (Ctrl-C from terminal)Process started by script does not receive SIGINTWhy does closing terminal emulator window terminate a bash process with SIGHUP trap changed not to terminate?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a Bash script that launches a Python program. The Bash script handles SIGINT, SIGTERM and SIGHUP signals to do a cleanup operation. I noticed that when I close the process in a tab in LXTerminal, the cleanup process happens. But when I close the entire terminal window, the cleanup process closes.
What am I missing to have the cleanup process to happen?
bash signals
bumped to the homepage by Community♦ 2 days ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I have a Bash script that launches a Python program. The Bash script handles SIGINT, SIGTERM and SIGHUP signals to do a cleanup operation. I noticed that when I close the process in a tab in LXTerminal, the cleanup process happens. But when I close the entire terminal window, the cleanup process closes.
What am I missing to have the cleanup process to happen?
bash signals
bumped to the homepage by Community♦ 2 days ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
Have you tried usingstrace?
– Wildcard
Oct 8 '15 at 1:32
2
OP says the script handlesSIGHUP; howeverSIGHUPis what I see when testing this. Lacking a script to demonstrate the problem, there's nothing to test.
– Thomas Dickey
Oct 16 '16 at 20:21
The process is probably "closing" because it gets a I/O error when still trying to read or write to the terminal after receiving the SIGHUP informing it that the terminal has been torn up and is no longer usable.
– mosvy
2 days ago
also see this unix.stackexchange.com/questions/491626/…
– mosvy
2 days ago
add a comment |
I have a Bash script that launches a Python program. The Bash script handles SIGINT, SIGTERM and SIGHUP signals to do a cleanup operation. I noticed that when I close the process in a tab in LXTerminal, the cleanup process happens. But when I close the entire terminal window, the cleanup process closes.
What am I missing to have the cleanup process to happen?
bash signals
I have a Bash script that launches a Python program. The Bash script handles SIGINT, SIGTERM and SIGHUP signals to do a cleanup operation. I noticed that when I close the process in a tab in LXTerminal, the cleanup process happens. But when I close the entire terminal window, the cleanup process closes.
What am I missing to have the cleanup process to happen?
bash signals
bash signals
edited Jan 6 '17 at 13:24
janos
7,31722548
7,31722548
asked Oct 7 '15 at 19:38
user3346931user3346931
10017
10017
bumped to the homepage by Community♦ 2 days ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 2 days ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
Have you tried usingstrace?
– Wildcard
Oct 8 '15 at 1:32
2
OP says the script handlesSIGHUP; howeverSIGHUPis what I see when testing this. Lacking a script to demonstrate the problem, there's nothing to test.
– Thomas Dickey
Oct 16 '16 at 20:21
The process is probably "closing" because it gets a I/O error when still trying to read or write to the terminal after receiving the SIGHUP informing it that the terminal has been torn up and is no longer usable.
– mosvy
2 days ago
also see this unix.stackexchange.com/questions/491626/…
– mosvy
2 days ago
add a comment |
Have you tried usingstrace?
– Wildcard
Oct 8 '15 at 1:32
2
OP says the script handlesSIGHUP; howeverSIGHUPis what I see when testing this. Lacking a script to demonstrate the problem, there's nothing to test.
– Thomas Dickey
Oct 16 '16 at 20:21
The process is probably "closing" because it gets a I/O error when still trying to read or write to the terminal after receiving the SIGHUP informing it that the terminal has been torn up and is no longer usable.
– mosvy
2 days ago
also see this unix.stackexchange.com/questions/491626/…
– mosvy
2 days ago
Have you tried using
strace?– Wildcard
Oct 8 '15 at 1:32
Have you tried using
strace?– Wildcard
Oct 8 '15 at 1:32
2
2
OP says the script handles
SIGHUP; however SIGHUP is what I see when testing this. Lacking a script to demonstrate the problem, there's nothing to test.– Thomas Dickey
Oct 16 '16 at 20:21
OP says the script handles
SIGHUP; however SIGHUP is what I see when testing this. Lacking a script to demonstrate the problem, there's nothing to test.– Thomas Dickey
Oct 16 '16 at 20:21
The process is probably "closing" because it gets a I/O error when still trying to read or write to the terminal after receiving the SIGHUP informing it that the terminal has been torn up and is no longer usable.
– mosvy
2 days ago
The process is probably "closing" because it gets a I/O error when still trying to read or write to the terminal after receiving the SIGHUP informing it that the terminal has been torn up and is no longer usable.
– mosvy
2 days ago
also see this unix.stackexchange.com/questions/491626/…
– mosvy
2 days ago
also see this unix.stackexchange.com/questions/491626/…
– mosvy
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
Here's a script that generates a script that will try to catch all signals. The script it generates (sigcatcher.sh) outputs the name of the caught signal before exiting.
#!/bin/sh
# generate a shell function for each and every available signal.
/bin/kill -l | tr ' ' 'n' |
while read signal; do
cat <<END_OF_FUNCTION
handle_$signal ()
echo "Caught $signal"
exit
trap 'handle_$signal' $signal
END_OF_FUNCTION
done >sigcatcher.sh
echo 'echo "$$"; sleep 600' >>sigcatcher.sh
On my system (OpenBSD), /bin/kill -l generates a list of available signals on one line, that's why the tr is there to break it up.
The generated script will look something like this:
handle_HUP ()
echo "Caught HUP"
exit
trap 'handle_HUP' HUP
handle_INT ()
echo "Caught INT"
exit
trap 'handle_INT' INT
(etc.)
And it will be finished off with
echo "$$"; sleep 600
It outputs its PID and sleeps for 10 minutes.
You run it like this:
$ sh ./sigcatcher.sh >sigcatcher.out
Then you close the window, and then you inspect sigcatcher.out.
I don't run X Windows, but when I kill the tmux pane that this script is running in, I get "Caught HUP" in the output file.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f234611%2fwhat-signal-is-sent-when-you-close-a-bash-terminal-to-the-programs-it-was-runnin%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Here's a script that generates a script that will try to catch all signals. The script it generates (sigcatcher.sh) outputs the name of the caught signal before exiting.
#!/bin/sh
# generate a shell function for each and every available signal.
/bin/kill -l | tr ' ' 'n' |
while read signal; do
cat <<END_OF_FUNCTION
handle_$signal ()
echo "Caught $signal"
exit
trap 'handle_$signal' $signal
END_OF_FUNCTION
done >sigcatcher.sh
echo 'echo "$$"; sleep 600' >>sigcatcher.sh
On my system (OpenBSD), /bin/kill -l generates a list of available signals on one line, that's why the tr is there to break it up.
The generated script will look something like this:
handle_HUP ()
echo "Caught HUP"
exit
trap 'handle_HUP' HUP
handle_INT ()
echo "Caught INT"
exit
trap 'handle_INT' INT
(etc.)
And it will be finished off with
echo "$$"; sleep 600
It outputs its PID and sleeps for 10 minutes.
You run it like this:
$ sh ./sigcatcher.sh >sigcatcher.out
Then you close the window, and then you inspect sigcatcher.out.
I don't run X Windows, but when I kill the tmux pane that this script is running in, I get "Caught HUP" in the output file.
add a comment |
Here's a script that generates a script that will try to catch all signals. The script it generates (sigcatcher.sh) outputs the name of the caught signal before exiting.
#!/bin/sh
# generate a shell function for each and every available signal.
/bin/kill -l | tr ' ' 'n' |
while read signal; do
cat <<END_OF_FUNCTION
handle_$signal ()
echo "Caught $signal"
exit
trap 'handle_$signal' $signal
END_OF_FUNCTION
done >sigcatcher.sh
echo 'echo "$$"; sleep 600' >>sigcatcher.sh
On my system (OpenBSD), /bin/kill -l generates a list of available signals on one line, that's why the tr is there to break it up.
The generated script will look something like this:
handle_HUP ()
echo "Caught HUP"
exit
trap 'handle_HUP' HUP
handle_INT ()
echo "Caught INT"
exit
trap 'handle_INT' INT
(etc.)
And it will be finished off with
echo "$$"; sleep 600
It outputs its PID and sleeps for 10 minutes.
You run it like this:
$ sh ./sigcatcher.sh >sigcatcher.out
Then you close the window, and then you inspect sigcatcher.out.
I don't run X Windows, but when I kill the tmux pane that this script is running in, I get "Caught HUP" in the output file.
add a comment |
Here's a script that generates a script that will try to catch all signals. The script it generates (sigcatcher.sh) outputs the name of the caught signal before exiting.
#!/bin/sh
# generate a shell function for each and every available signal.
/bin/kill -l | tr ' ' 'n' |
while read signal; do
cat <<END_OF_FUNCTION
handle_$signal ()
echo "Caught $signal"
exit
trap 'handle_$signal' $signal
END_OF_FUNCTION
done >sigcatcher.sh
echo 'echo "$$"; sleep 600' >>sigcatcher.sh
On my system (OpenBSD), /bin/kill -l generates a list of available signals on one line, that's why the tr is there to break it up.
The generated script will look something like this:
handle_HUP ()
echo "Caught HUP"
exit
trap 'handle_HUP' HUP
handle_INT ()
echo "Caught INT"
exit
trap 'handle_INT' INT
(etc.)
And it will be finished off with
echo "$$"; sleep 600
It outputs its PID and sleeps for 10 minutes.
You run it like this:
$ sh ./sigcatcher.sh >sigcatcher.out
Then you close the window, and then you inspect sigcatcher.out.
I don't run X Windows, but when I kill the tmux pane that this script is running in, I get "Caught HUP" in the output file.
Here's a script that generates a script that will try to catch all signals. The script it generates (sigcatcher.sh) outputs the name of the caught signal before exiting.
#!/bin/sh
# generate a shell function for each and every available signal.
/bin/kill -l | tr ' ' 'n' |
while read signal; do
cat <<END_OF_FUNCTION
handle_$signal ()
echo "Caught $signal"
exit
trap 'handle_$signal' $signal
END_OF_FUNCTION
done >sigcatcher.sh
echo 'echo "$$"; sleep 600' >>sigcatcher.sh
On my system (OpenBSD), /bin/kill -l generates a list of available signals on one line, that's why the tr is there to break it up.
The generated script will look something like this:
handle_HUP ()
echo "Caught HUP"
exit
trap 'handle_HUP' HUP
handle_INT ()
echo "Caught INT"
exit
trap 'handle_INT' INT
(etc.)
And it will be finished off with
echo "$$"; sleep 600
It outputs its PID and sleeps for 10 minutes.
You run it like this:
$ sh ./sigcatcher.sh >sigcatcher.out
Then you close the window, and then you inspect sigcatcher.out.
I don't run X Windows, but when I kill the tmux pane that this script is running in, I get "Caught HUP" in the output file.
answered Jan 6 '17 at 13:57
Kusalananda♦Kusalananda
140k17261435
140k17261435
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f234611%2fwhat-signal-is-sent-when-you-close-a-bash-terminal-to-the-programs-it-was-runnin%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Have you tried using
strace?– Wildcard
Oct 8 '15 at 1:32
2
OP says the script handles
SIGHUP; howeverSIGHUPis what I see when testing this. Lacking a script to demonstrate the problem, there's nothing to test.– Thomas Dickey
Oct 16 '16 at 20:21
The process is probably "closing" because it gets a I/O error when still trying to read or write to the terminal after receiving the SIGHUP informing it that the terminal has been torn up and is no longer usable.
– mosvy
2 days ago
also see this unix.stackexchange.com/questions/491626/…
– mosvy
2 days ago