Run a command for a specified time and then abort if time exceeds

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











up vote
41
down vote

favorite
12












I want know how I can run a command for a specified time say, one minute and if it doesn't complete execution then I should be able to stop it.







share|improve this question
























    up vote
    41
    down vote

    favorite
    12












    I want know how I can run a command for a specified time say, one minute and if it doesn't complete execution then I should be able to stop it.







    share|improve this question






















      up vote
      41
      down vote

      favorite
      12









      up vote
      41
      down vote

      favorite
      12






      12





      I want know how I can run a command for a specified time say, one minute and if it doesn't complete execution then I should be able to stop it.







      share|improve this question












      I want know how I can run a command for a specified time say, one minute and if it doesn't complete execution then I should be able to stop it.









      share|improve this question











      share|improve this question




      share|improve this question










      asked Oct 23 '11 at 15:34









      nikhil

      4171616




      4171616




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          51
          down vote



          accepted










          Use timeout:



          NAME
          timeout - run a command with a time limit

          SYNOPSIS
          timeout [OPTION] DURATION COMMAND [ARG]...
          timeout [OPTION]


          (Just in case, if you don't have this command or if you need to be compatible with very very old shells and have several other utterly specific requirements… have a look at this this question ;-))






          share|improve this answer


















          • 1




            Perfect, thanks for linking to that question. I didn't have timeout on my system but I do now. Just on a side note, is timeout bundled with the majority of linux distributions?
            – nikhil
            Oct 24 '11 at 4:28






          • 1




            Pretty cool. you can do something like this: for i in `seq 0 3`; do timeout 2 ethtool -p eth$i; done; to blink LED's on NIC's
            – user1527227
            Jun 19 '14 at 16:42







          • 1




            What a sexy command. Thanks for pointing it out, wasn't aware of it.
            – Bruno Bieri
            Mar 16 '17 at 14:16










          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%2f23145%2frun-a-command-for-a-specified-time-and-then-abort-if-time-exceeds%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
          51
          down vote



          accepted










          Use timeout:



          NAME
          timeout - run a command with a time limit

          SYNOPSIS
          timeout [OPTION] DURATION COMMAND [ARG]...
          timeout [OPTION]


          (Just in case, if you don't have this command or if you need to be compatible with very very old shells and have several other utterly specific requirements… have a look at this this question ;-))






          share|improve this answer


















          • 1




            Perfect, thanks for linking to that question. I didn't have timeout on my system but I do now. Just on a side note, is timeout bundled with the majority of linux distributions?
            – nikhil
            Oct 24 '11 at 4:28






          • 1




            Pretty cool. you can do something like this: for i in `seq 0 3`; do timeout 2 ethtool -p eth$i; done; to blink LED's on NIC's
            – user1527227
            Jun 19 '14 at 16:42







          • 1




            What a sexy command. Thanks for pointing it out, wasn't aware of it.
            – Bruno Bieri
            Mar 16 '17 at 14:16














          up vote
          51
          down vote



          accepted










          Use timeout:



          NAME
          timeout - run a command with a time limit

          SYNOPSIS
          timeout [OPTION] DURATION COMMAND [ARG]...
          timeout [OPTION]


          (Just in case, if you don't have this command or if you need to be compatible with very very old shells and have several other utterly specific requirements… have a look at this this question ;-))






          share|improve this answer


















          • 1




            Perfect, thanks for linking to that question. I didn't have timeout on my system but I do now. Just on a side note, is timeout bundled with the majority of linux distributions?
            – nikhil
            Oct 24 '11 at 4:28






          • 1




            Pretty cool. you can do something like this: for i in `seq 0 3`; do timeout 2 ethtool -p eth$i; done; to blink LED's on NIC's
            – user1527227
            Jun 19 '14 at 16:42







          • 1




            What a sexy command. Thanks for pointing it out, wasn't aware of it.
            – Bruno Bieri
            Mar 16 '17 at 14:16












          up vote
          51
          down vote



          accepted







          up vote
          51
          down vote



          accepted






          Use timeout:



          NAME
          timeout - run a command with a time limit

          SYNOPSIS
          timeout [OPTION] DURATION COMMAND [ARG]...
          timeout [OPTION]


          (Just in case, if you don't have this command or if you need to be compatible with very very old shells and have several other utterly specific requirements… have a look at this this question ;-))






          share|improve this answer














          Use timeout:



          NAME
          timeout - run a command with a time limit

          SYNOPSIS
          timeout [OPTION] DURATION COMMAND [ARG]...
          timeout [OPTION]


          (Just in case, if you don't have this command or if you need to be compatible with very very old shells and have several other utterly specific requirements… have a look at this this question ;-))







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Apr 13 '17 at 12:36









          Community♦

          1




          1










          answered Oct 23 '11 at 15:41









          Stéphane Gimenez

          18.6k15074




          18.6k15074







          • 1




            Perfect, thanks for linking to that question. I didn't have timeout on my system but I do now. Just on a side note, is timeout bundled with the majority of linux distributions?
            – nikhil
            Oct 24 '11 at 4:28






          • 1




            Pretty cool. you can do something like this: for i in `seq 0 3`; do timeout 2 ethtool -p eth$i; done; to blink LED's on NIC's
            – user1527227
            Jun 19 '14 at 16:42







          • 1




            What a sexy command. Thanks for pointing it out, wasn't aware of it.
            – Bruno Bieri
            Mar 16 '17 at 14:16












          • 1




            Perfect, thanks for linking to that question. I didn't have timeout on my system but I do now. Just on a side note, is timeout bundled with the majority of linux distributions?
            – nikhil
            Oct 24 '11 at 4:28






          • 1




            Pretty cool. you can do something like this: for i in `seq 0 3`; do timeout 2 ethtool -p eth$i; done; to blink LED's on NIC's
            – user1527227
            Jun 19 '14 at 16:42







          • 1




            What a sexy command. Thanks for pointing it out, wasn't aware of it.
            – Bruno Bieri
            Mar 16 '17 at 14:16







          1




          1




          Perfect, thanks for linking to that question. I didn't have timeout on my system but I do now. Just on a side note, is timeout bundled with the majority of linux distributions?
          – nikhil
          Oct 24 '11 at 4:28




          Perfect, thanks for linking to that question. I didn't have timeout on my system but I do now. Just on a side note, is timeout bundled with the majority of linux distributions?
          – nikhil
          Oct 24 '11 at 4:28




          1




          1




          Pretty cool. you can do something like this: for i in `seq 0 3`; do timeout 2 ethtool -p eth$i; done; to blink LED's on NIC's
          – user1527227
          Jun 19 '14 at 16:42





          Pretty cool. you can do something like this: for i in `seq 0 3`; do timeout 2 ethtool -p eth$i; done; to blink LED's on NIC's
          – user1527227
          Jun 19 '14 at 16:42





          1




          1




          What a sexy command. Thanks for pointing it out, wasn't aware of it.
          – Bruno Bieri
          Mar 16 '17 at 14:16




          What a sexy command. Thanks for pointing it out, wasn't aware of it.
          – Bruno Bieri
          Mar 16 '17 at 14:16












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f23145%2frun-a-command-for-a-specified-time-and-then-abort-if-time-exceeds%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?