checking the status of an ongoing “sleep” process from the terminal

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











up vote
3
down vote

favorite












Is there a way to check how long a running "sleep" process has left to go before it ends within the terminal?







share|improve this question























    up vote
    3
    down vote

    favorite












    Is there a way to check how long a running "sleep" process has left to go before it ends within the terminal?







    share|improve this question





















      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      Is there a way to check how long a running "sleep" process has left to go before it ends within the terminal?







      share|improve this question











      Is there a way to check how long a running "sleep" process has left to go before it ends within the terminal?









      share|improve this question










      share|improve this question




      share|improve this question









      asked Aug 6 at 18:43









      BarryBluejeans

      585




      585




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          The sleep command in itself offers no service that allows the monitoring of the remaining sleep time. It is also not displayed anywhere.



          As the sleep command operates without issuing a series of system calls for the kernel, you won't be able to use a typical debugging tool such as dtruss either. If you try to use the lldb debugger to attach to the process, you'll find that the sleep command is also interrupted and cannot be continued.



          So it is not as such possible to very precisely determine the amount of time left. If you can make do with an imprecise result, do the following:



          First run this command:



          ps xa | grep sleep


          This should show you the sleep command with the number of seconds that it is supposed to sleep in total. For example:



          1234 s0123 S+ 0:00.01 sleep 789


          Here 789 is the number of seconds that the command is supposed to sleep in total.



          Then afterwards run this command:



          ps xa -o etime,command -c | grep sleep


          It will show you the total time the process has been running:



           03:15 sleep


          This means that the process has sleep for 3 minutes and 15 seconds = 195 seconds. The remaining sleep time is 789 - 195 = 594 seconds.






          share|improve this answer




























            up vote
            2
            down vote













            If your version of ps supports etimes (etime in seconds) (unfortunately not supported on MacOS), you can use this to calculate the remaining time:



            ps xa -o etimes,command | awk '/[s]leep/ print "time remaining for", $2, "is", $3 - $1, "seconds"'


            Example output:



            time remaining for sleep is 94 seconds


            Or you can simplify that to only show the number:



            ps xa -o etimes,command | awk '/[s]leep/ print $3 - $1'


            These commands will output more than one line if more than one sleep process is running.



            Note: Neither etime nor etimes outputs fractional seconds, but sleep can accept them as an argument. This will likely affect the accuracy of your calculation.



            For MacOS and others without etimes, you can convert etime (ddd-hh:mm:ss) to seconds reversing the calculations done in the source of ps (in print.c):



            ps xa -o etimes,command | awk '
            BEGIN
            f = "1 60 3600 86400";
            split(f, factors)

            /[s]leep/
            split($1, parts, "[-:]");
            count = length(parts);
            for (i = count; i > 0; i--)
            e += parts[i] * factors[count + 1 - i]
            ;
            print e;
            e = 0
            '





            share|improve this answer























              Your Answer







              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "118"
              ;
              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%2fapple.stackexchange.com%2fquestions%2f333012%2fchecking-the-status-of-an-ongoing-sleep-process-from-the-terminal%23new-answer', 'question_page');

              );

              Post as a guest






























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              4
              down vote



              accepted










              The sleep command in itself offers no service that allows the monitoring of the remaining sleep time. It is also not displayed anywhere.



              As the sleep command operates without issuing a series of system calls for the kernel, you won't be able to use a typical debugging tool such as dtruss either. If you try to use the lldb debugger to attach to the process, you'll find that the sleep command is also interrupted and cannot be continued.



              So it is not as such possible to very precisely determine the amount of time left. If you can make do with an imprecise result, do the following:



              First run this command:



              ps xa | grep sleep


              This should show you the sleep command with the number of seconds that it is supposed to sleep in total. For example:



              1234 s0123 S+ 0:00.01 sleep 789


              Here 789 is the number of seconds that the command is supposed to sleep in total.



              Then afterwards run this command:



              ps xa -o etime,command -c | grep sleep


              It will show you the total time the process has been running:



               03:15 sleep


              This means that the process has sleep for 3 minutes and 15 seconds = 195 seconds. The remaining sleep time is 789 - 195 = 594 seconds.






              share|improve this answer

























                up vote
                4
                down vote



                accepted










                The sleep command in itself offers no service that allows the monitoring of the remaining sleep time. It is also not displayed anywhere.



                As the sleep command operates without issuing a series of system calls for the kernel, you won't be able to use a typical debugging tool such as dtruss either. If you try to use the lldb debugger to attach to the process, you'll find that the sleep command is also interrupted and cannot be continued.



                So it is not as such possible to very precisely determine the amount of time left. If you can make do with an imprecise result, do the following:



                First run this command:



                ps xa | grep sleep


                This should show you the sleep command with the number of seconds that it is supposed to sleep in total. For example:



                1234 s0123 S+ 0:00.01 sleep 789


                Here 789 is the number of seconds that the command is supposed to sleep in total.



                Then afterwards run this command:



                ps xa -o etime,command -c | grep sleep


                It will show you the total time the process has been running:



                 03:15 sleep


                This means that the process has sleep for 3 minutes and 15 seconds = 195 seconds. The remaining sleep time is 789 - 195 = 594 seconds.






                share|improve this answer























                  up vote
                  4
                  down vote



                  accepted







                  up vote
                  4
                  down vote



                  accepted






                  The sleep command in itself offers no service that allows the monitoring of the remaining sleep time. It is also not displayed anywhere.



                  As the sleep command operates without issuing a series of system calls for the kernel, you won't be able to use a typical debugging tool such as dtruss either. If you try to use the lldb debugger to attach to the process, you'll find that the sleep command is also interrupted and cannot be continued.



                  So it is not as such possible to very precisely determine the amount of time left. If you can make do with an imprecise result, do the following:



                  First run this command:



                  ps xa | grep sleep


                  This should show you the sleep command with the number of seconds that it is supposed to sleep in total. For example:



                  1234 s0123 S+ 0:00.01 sleep 789


                  Here 789 is the number of seconds that the command is supposed to sleep in total.



                  Then afterwards run this command:



                  ps xa -o etime,command -c | grep sleep


                  It will show you the total time the process has been running:



                   03:15 sleep


                  This means that the process has sleep for 3 minutes and 15 seconds = 195 seconds. The remaining sleep time is 789 - 195 = 594 seconds.






                  share|improve this answer













                  The sleep command in itself offers no service that allows the monitoring of the remaining sleep time. It is also not displayed anywhere.



                  As the sleep command operates without issuing a series of system calls for the kernel, you won't be able to use a typical debugging tool such as dtruss either. If you try to use the lldb debugger to attach to the process, you'll find that the sleep command is also interrupted and cannot be continued.



                  So it is not as such possible to very precisely determine the amount of time left. If you can make do with an imprecise result, do the following:



                  First run this command:



                  ps xa | grep sleep


                  This should show you the sleep command with the number of seconds that it is supposed to sleep in total. For example:



                  1234 s0123 S+ 0:00.01 sleep 789


                  Here 789 is the number of seconds that the command is supposed to sleep in total.



                  Then afterwards run this command:



                  ps xa -o etime,command -c | grep sleep


                  It will show you the total time the process has been running:



                   03:15 sleep


                  This means that the process has sleep for 3 minutes and 15 seconds = 195 seconds. The remaining sleep time is 789 - 195 = 594 seconds.







                  share|improve this answer













                  share|improve this answer



                  share|improve this answer











                  answered Aug 6 at 20:05









                  jksoegaard

                  11.5k1534




                  11.5k1534






















                      up vote
                      2
                      down vote













                      If your version of ps supports etimes (etime in seconds) (unfortunately not supported on MacOS), you can use this to calculate the remaining time:



                      ps xa -o etimes,command | awk '/[s]leep/ print "time remaining for", $2, "is", $3 - $1, "seconds"'


                      Example output:



                      time remaining for sleep is 94 seconds


                      Or you can simplify that to only show the number:



                      ps xa -o etimes,command | awk '/[s]leep/ print $3 - $1'


                      These commands will output more than one line if more than one sleep process is running.



                      Note: Neither etime nor etimes outputs fractional seconds, but sleep can accept them as an argument. This will likely affect the accuracy of your calculation.



                      For MacOS and others without etimes, you can convert etime (ddd-hh:mm:ss) to seconds reversing the calculations done in the source of ps (in print.c):



                      ps xa -o etimes,command | awk '
                      BEGIN
                      f = "1 60 3600 86400";
                      split(f, factors)

                      /[s]leep/
                      split($1, parts, "[-:]");
                      count = length(parts);
                      for (i = count; i > 0; i--)
                      e += parts[i] * factors[count + 1 - i]
                      ;
                      print e;
                      e = 0
                      '





                      share|improve this answer



























                        up vote
                        2
                        down vote













                        If your version of ps supports etimes (etime in seconds) (unfortunately not supported on MacOS), you can use this to calculate the remaining time:



                        ps xa -o etimes,command | awk '/[s]leep/ print "time remaining for", $2, "is", $3 - $1, "seconds"'


                        Example output:



                        time remaining for sleep is 94 seconds


                        Or you can simplify that to only show the number:



                        ps xa -o etimes,command | awk '/[s]leep/ print $3 - $1'


                        These commands will output more than one line if more than one sleep process is running.



                        Note: Neither etime nor etimes outputs fractional seconds, but sleep can accept them as an argument. This will likely affect the accuracy of your calculation.



                        For MacOS and others without etimes, you can convert etime (ddd-hh:mm:ss) to seconds reversing the calculations done in the source of ps (in print.c):



                        ps xa -o etimes,command | awk '
                        BEGIN
                        f = "1 60 3600 86400";
                        split(f, factors)

                        /[s]leep/
                        split($1, parts, "[-:]");
                        count = length(parts);
                        for (i = count; i > 0; i--)
                        e += parts[i] * factors[count + 1 - i]
                        ;
                        print e;
                        e = 0
                        '





                        share|improve this answer

























                          up vote
                          2
                          down vote










                          up vote
                          2
                          down vote









                          If your version of ps supports etimes (etime in seconds) (unfortunately not supported on MacOS), you can use this to calculate the remaining time:



                          ps xa -o etimes,command | awk '/[s]leep/ print "time remaining for", $2, "is", $3 - $1, "seconds"'


                          Example output:



                          time remaining for sleep is 94 seconds


                          Or you can simplify that to only show the number:



                          ps xa -o etimes,command | awk '/[s]leep/ print $3 - $1'


                          These commands will output more than one line if more than one sleep process is running.



                          Note: Neither etime nor etimes outputs fractional seconds, but sleep can accept them as an argument. This will likely affect the accuracy of your calculation.



                          For MacOS and others without etimes, you can convert etime (ddd-hh:mm:ss) to seconds reversing the calculations done in the source of ps (in print.c):



                          ps xa -o etimes,command | awk '
                          BEGIN
                          f = "1 60 3600 86400";
                          split(f, factors)

                          /[s]leep/
                          split($1, parts, "[-:]");
                          count = length(parts);
                          for (i = count; i > 0; i--)
                          e += parts[i] * factors[count + 1 - i]
                          ;
                          print e;
                          e = 0
                          '





                          share|improve this answer















                          If your version of ps supports etimes (etime in seconds) (unfortunately not supported on MacOS), you can use this to calculate the remaining time:



                          ps xa -o etimes,command | awk '/[s]leep/ print "time remaining for", $2, "is", $3 - $1, "seconds"'


                          Example output:



                          time remaining for sleep is 94 seconds


                          Or you can simplify that to only show the number:



                          ps xa -o etimes,command | awk '/[s]leep/ print $3 - $1'


                          These commands will output more than one line if more than one sleep process is running.



                          Note: Neither etime nor etimes outputs fractional seconds, but sleep can accept them as an argument. This will likely affect the accuracy of your calculation.



                          For MacOS and others without etimes, you can convert etime (ddd-hh:mm:ss) to seconds reversing the calculations done in the source of ps (in print.c):



                          ps xa -o etimes,command | awk '
                          BEGIN
                          f = "1 60 3600 86400";
                          split(f, factors)

                          /[s]leep/
                          split($1, parts, "[-:]");
                          count = length(parts);
                          for (i = count; i > 0; i--)
                          e += parts[i] * factors[count + 1 - i]
                          ;
                          print e;
                          e = 0
                          '






                          share|improve this answer















                          share|improve this answer



                          share|improve this answer








                          edited Aug 7 at 20:54


























                          answered Aug 6 at 23:30









                          Dennis Williamson

                          121115




                          121115






















                               

                              draft saved


                              draft discarded


























                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fapple.stackexchange.com%2fquestions%2f333012%2fchecking-the-status-of-an-ongoing-sleep-process-from-the-terminal%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Comments

                              Popular posts from this blog

                              What is the equation of a 3D cone with generalised tilt?

                              Relationship between determinant of matrix and determinant of adjoint?

                              Color the edges and diagonals of a regular polygon