How can I test that the bash interactive shell handles the signal using the handler that I set up via `trap`?

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











up vote
0
down vote

favorite












In a bash interactive shell, when I run a trap command (e.g. trap "echo You hit control-C!" INT) to set up a signal handler, does that set up how the bash interactive shell handles the signal?



How can I test that the bash interactive shell handles the signal by using the handler that I set up via trap?



Is it possible to test i.e. to generate the signal



  • within the bash interactive shell?

  • within the terminal emulator where the shell runs?

Or must I test from the outside of the bash interactive shell, or outside the terminal emulator?



Thanks.







share|improve this question




















  • What do you expect to happen, and what's happening instead? The definition of trap is "The commands in arg are to be read and executed when the shell receives signal sigspec."
    – Jeff Schaller
    Oct 19 '17 at 23:38










  • I would like to know how to show that an interactive shell reacts to a signal for which a trap has been set in it.
    – Tim
    Oct 20 '17 at 1:17















up vote
0
down vote

favorite












In a bash interactive shell, when I run a trap command (e.g. trap "echo You hit control-C!" INT) to set up a signal handler, does that set up how the bash interactive shell handles the signal?



How can I test that the bash interactive shell handles the signal by using the handler that I set up via trap?



Is it possible to test i.e. to generate the signal



  • within the bash interactive shell?

  • within the terminal emulator where the shell runs?

Or must I test from the outside of the bash interactive shell, or outside the terminal emulator?



Thanks.







share|improve this question




















  • What do you expect to happen, and what's happening instead? The definition of trap is "The commands in arg are to be read and executed when the shell receives signal sigspec."
    – Jeff Schaller
    Oct 19 '17 at 23:38










  • I would like to know how to show that an interactive shell reacts to a signal for which a trap has been set in it.
    – Tim
    Oct 20 '17 at 1:17













up vote
0
down vote

favorite









up vote
0
down vote

favorite











In a bash interactive shell, when I run a trap command (e.g. trap "echo You hit control-C!" INT) to set up a signal handler, does that set up how the bash interactive shell handles the signal?



How can I test that the bash interactive shell handles the signal by using the handler that I set up via trap?



Is it possible to test i.e. to generate the signal



  • within the bash interactive shell?

  • within the terminal emulator where the shell runs?

Or must I test from the outside of the bash interactive shell, or outside the terminal emulator?



Thanks.







share|improve this question












In a bash interactive shell, when I run a trap command (e.g. trap "echo You hit control-C!" INT) to set up a signal handler, does that set up how the bash interactive shell handles the signal?



How can I test that the bash interactive shell handles the signal by using the handler that I set up via trap?



Is it possible to test i.e. to generate the signal



  • within the bash interactive shell?

  • within the terminal emulator where the shell runs?

Or must I test from the outside of the bash interactive shell, or outside the terminal emulator?



Thanks.









share|improve this question











share|improve this question




share|improve this question










asked Oct 19 '17 at 22:44









Tim

22.9k66225407




22.9k66225407











  • What do you expect to happen, and what's happening instead? The definition of trap is "The commands in arg are to be read and executed when the shell receives signal sigspec."
    – Jeff Schaller
    Oct 19 '17 at 23:38










  • I would like to know how to show that an interactive shell reacts to a signal for which a trap has been set in it.
    – Tim
    Oct 20 '17 at 1:17

















  • What do you expect to happen, and what's happening instead? The definition of trap is "The commands in arg are to be read and executed when the shell receives signal sigspec."
    – Jeff Schaller
    Oct 19 '17 at 23:38










  • I would like to know how to show that an interactive shell reacts to a signal for which a trap has been set in it.
    – Tim
    Oct 20 '17 at 1:17
















What do you expect to happen, and what's happening instead? The definition of trap is "The commands in arg are to be read and executed when the shell receives signal sigspec."
– Jeff Schaller
Oct 19 '17 at 23:38




What do you expect to happen, and what's happening instead? The definition of trap is "The commands in arg are to be read and executed when the shell receives signal sigspec."
– Jeff Schaller
Oct 19 '17 at 23:38












I would like to know how to show that an interactive shell reacts to a signal for which a trap has been set in it.
– Tim
Oct 20 '17 at 1:17





I would like to know how to show that an interactive shell reacts to a signal for which a trap has been set in it.
– Tim
Oct 20 '17 at 1:17











1 Answer
1






active

oldest

votes

















up vote
3
down vote



accepted










You can test a handler from inside the shell it’s set up in, by using kill to send a signal to the current shell:



kill -INT $$


Change -INT to match the trap you wish to test.






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',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    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%2f399231%2fhow-can-i-test-that-the-bash-interactive-shell-handles-the-signal-using-the-hand%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    3
    down vote



    accepted










    You can test a handler from inside the shell it’s set up in, by using kill to send a signal to the current shell:



    kill -INT $$


    Change -INT to match the trap you wish to test.






    share|improve this answer
























      up vote
      3
      down vote



      accepted










      You can test a handler from inside the shell it’s set up in, by using kill to send a signal to the current shell:



      kill -INT $$


      Change -INT to match the trap you wish to test.






      share|improve this answer






















        up vote
        3
        down vote



        accepted







        up vote
        3
        down vote



        accepted






        You can test a handler from inside the shell it’s set up in, by using kill to send a signal to the current shell:



        kill -INT $$


        Change -INT to match the trap you wish to test.






        share|improve this answer












        You can test a handler from inside the shell it’s set up in, by using kill to send a signal to the current shell:



        kill -INT $$


        Change -INT to match the trap you wish to test.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Oct 20 '17 at 4:23









        Stephen Kitt

        144k22314378




        144k22314378



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f399231%2fhow-can-i-test-that-the-bash-interactive-shell-handles-the-signal-using-the-hand%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

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

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?