From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: The Halting Problem
Date: Sat, 28 Dec 2013 12:43:48 -0800 [thread overview]
Message-ID: <131228124348.ZM27114@torch.brasslantern.com> (raw)
In-Reply-To: <20131228164937.GA44192@cs2666372x.uwec.edu>
On Dec 28, 10:49am, Chris Johnson wrote:
}
} I tried backgrounding the long-running job, capturing its PID, and
} passing that to sleepkill as the process to kill:
}
} java Foo &
} longpid=$!
}
} sleepkill $longpid &
} sleeppid=$!
}
} wait $longpid
} # Kill the sleep timer, if necessary.
} kill $sleeppid 2>/dev/null
}
} This kills the long-running job on timeout, but it also puts the job
} in the background. Control-C won't kill it.
You're almost there. If ctrl+c won't kill the java process in the above
example, then there's some additional signal handling going on behind
the scenes, and you just need to add a trap before the "wait":
TRAPINT() { kill $longpid }
So that when wait is interrupted you send off a signal to java. You
probably also want to kill $sleeppid there, but because it's a shell
function it may ignore the default TERM signal, so:
TRAPINT() {
kill $longpid
kill -HUP -$$
}
That should clean everything up.
next prev parent reply other threads:[~2013-12-28 20:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-28 16:49 Chris Johnson
2013-12-28 20:43 ` Bart Schaefer [this message]
2013-12-29 13:35 ` Chris Johnson
2013-12-30 0:53 ` Mikael Magnusson
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=131228124348.ZM27114@torch.brasslantern.com \
--to=schaefer@brasslantern.com \
--cc=zsh-users@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).