Problem piping "jobs" ** Summary **
Elmar Schuetz
schuetz at iraul1.ira.uka.de
Fri Dec 9 22:11:10 AEST 1988
In article <733 at iraun1.ira.uka.de> I asked
> [whether it's possible to pipe the "jobs"-command or how to kill the
> job with the highest number.]
Up to now I got answers from
Mike Khaw <mkhaw at teknowledge-vaxc.ARPA>
Ruben Gamboa <ruben at mcc.COM>
Chris Torek <chris at mimsy.umd.EDU>
Jonathan Sweedler <nsc!taux01!cjosta at uni-dortmund.DE>
Michael Greim <greim at sbsvax.UUCP>
Maarten Litmaath <maart at cs.vu.nl>
Doug Gwyn <gwyn at brl.ARPA>
Everyone said that the shell built-in "jobs", when piped, forks a new subshell
which does NOT have job control enabled. Thus, it can't show any jobs of the
parents' shell. The work-around would be to redirect the output to a temp file.
Michael suggested to make changes to the csh in order to do a 'kill -9 %#'.
And Doug mentioned there would be a solution in the BRL Bourne shell.
Mike offered two aliases. One to be asked for the job to be killed:
alias killbg 'jobs; echo -n "which one: "; kill -9 %$<'
and one to do what I wanted to do:
alias klast 'jobs > jobs$$; \
kill -9 %`tail -1 jobs$$ | \
sed '"'"'s/\[\([0-9]*\)\].*/\1/'"'"'`; \
rm -f jobs$$'
And a similar solution from Maarten:
jobs -l > /tmp/jobs$$
kill -9 `sed -n '$s/[^ ]*[^0-9]*\([0-9]*\).*/\1/p' /tmp/jobs$$`
My comment:
Mike's solution does not work with 'alias', but that doesn't matter.
Maarten's solution works fine and is faster without 'tail'.
So, many thanks to all who answered (i.e. Mike and Maarten for their effort)
and to all who's reply is on it's way.
Best regards, Elmar
--
There are many here among us who feel that life is but a joke. -- Bob Dylan
More information about the Comp.unix.questions
mailing list