How to kill only current process and continue with shell pipe-line?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












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 ?










share|improve this question


























    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 ?










    share|improve this question
























      0












      0








      0


      1






      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 ?










      share|improve this question














      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 ?







      bash command-line process-management






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jul 1 '15 at 10:06









      PremPrem

      1,52321229




      1,52321229




















          1 Answer
          1






          active

          oldest

          votes


















          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
          #





          share|improve this answer






















            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
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f213274%2fhow-to-kill-only-current-process-and-continue-with-shell-pipe-line%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









            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
            #





            share|improve this answer



























              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
              #





              share|improve this answer

























                0












                0








                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
                #





                share|improve this answer













                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
                #






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jul 1 '15 at 10:30









                dave_alcarindave_alcarin

                6261413




                6261413



























                    draft saved

                    draft discarded
















































                    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.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f213274%2fhow-to-kill-only-current-process-and-continue-with-shell-pipe-line%23new-answer', 'question_page');

                    );

                    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






                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Bahrain

                    Postfix configuration issue with fips on centos 7; mailgun relay