From: Alan Pinstein <apinstein@mac.com>
To: zsh-workers@zsh.org
Subject: Commands run from functions don't exit cleanly on terminal close (SIGHUP)?
Date: Wed, 24 Oct 2012 10:03:22 -0400 [thread overview]
Message-ID: <2B813FB0-0877-42BA-974C-1A142EF09BCE@mac.com> (raw)
I am having issues with ssh sessions not exiting when I closed the terminal window containing them.
I originally noticed this bug while using screen; I believe this bug/problem affects anyone that uses ssh/autossh/tmux/mxrvt/etc from inside a function. It causes screen to hang due to multiple concurrent connections that are orphaned on the client side.
I have reduced the problem down to whether or not the ssh command is executed directly in the shell, or from inside a function.
I isolated the issue from ssh as well; it seems that any command run from inside of a function doesn't cleanly exit when it receives a SIGHUP.
I managed to at least receive the signal before the child exits via TRAPS_ASYNC, but I can't figure out how to make the command die when the trap runs. I've tried "exit" and "return".
The function below reproduces the scenario easily.
willnotdie() {
echo 'try closing the terminal window while this runs (lasts 10s), notice that the php command is orphaned and does not die'
echo 'ps ax -o time,ppid,command | grep -v grep| grep "PPID\|php"'
echo 'if you run the PHP code in this script directly on the CLI, then it exists cleanly on terminal close'
setopt LOCAL_TRAPS LOCAL_OPTIONS TRAPS_ASYNC
echo -n "" > ./sig
(date && echo START) >> ./sig
trap '(date && echo HUP && exit 1) >> ./sig' HUP
trap '(date && echo INT) >> ./sig' INT
php -r '$i = time() + 10; while (true) { if (time() > $i) break; }'
(date && echo DONE) >> ./sig
}
# monitor the progress with this
while (true) do
ps ax -o time,ppid,command | grep -v grep| grep "PPID\|php"
sleep 1
done
I would appreciate any help.
Thanks in advance.
Alan
next reply other threads:[~2012-10-24 15:03 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-24 14:03 Alan Pinstein [this message]
2012-10-24 14:10 ` Alan Pinstein
2012-10-25 10:22 ` Peter Stephenson
2012-10-25 11:48 ` Alan Pinstein
2012-10-25 13:22 ` Alan Pinstein
2012-10-25 14:03 ` Peter Stephenson
2012-10-25 14:54 ` Bart Schaefer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2B813FB0-0877-42BA-974C-1A142EF09BCE@mac.com \
--to=apinstein@mac.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).