0

I have 2 related Doubts about Bash.

(Q1) Consider tail -f SomeFile | wc, a fictitious command-line, where tail is used to simulate a command (C1) which runs for a long time, with some output from time to time, and wc is used to simulate a command (C2) which processes that output when C1 finishes. After waiting for a long time (longer than usual) I want to see what output has been generated till now, so I want C1 to terminate. But pressing Ctrl-C will kill this whole pipeline. How can I kill only C1 ( or even a component of C1, if that is itself a compound command ) ?
If C1 had been looping over many files and grepping some text, but one file was from some hung nfs server, then I want to kill only that grep process.

(for F in A B C D E ; do grep sometext $F ; done) | wc

Here Ctrl-C will kill the whole command-line, but I want to kill only the currently running (or hung) process and continue with remaining files.

One solution I have, is to open a new connection, get the ps output, and "kill" it. I was wondering if there was a solution from Bash itself, such that some strange key-combination kills only the current process ?

(Q2) While trying to make examples for this question, I made this command-line,Here, where if I press Ctrl-C, I get an extra line of output, like this:

# echo `ping 127.0.0.1` | wc
^C

#

When backticks (``) are not used, the extra line is not there:

# tail -f SomeFile | wc
^C
#

Am I correct in thinking that since backticks (``) are handled by bash itself and, when the sub-process is killed, it is still considered as "empty output", so that is printed as the extra line ?

0

The command stty -a will show you all keyboard shortcuts. The only signals mapped are Ctrl-C (SIGINT), Ctrl-\ (SIGQUIT) and Ctrl-Z (SIGSUSP). There is no binding to other signals.

I would use the solution that you yourself said: separate shell, psoutput and killthe process you need killed.

To your second question, it is not because of the grave accents (``), but because of echo. Try this example:

# echo `sleep 10` | wc
^C

# `sleep 10` | wc
^C
# sleep `echo "10"` | wc
^C
#

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.