Using nohup and time with different outputs

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











up vote
0
down vote

favorite












I want to run an executable main and redirect all outputs to /dev/null, meanwhile I measure its runtime with time and write the results to runtime.out. Since the task is long I also have to run the whole thing with nohup.

I tried the following:

nohup time ./main &> /dev/null &> runtime.out &

This just outputs everything to runtime.out.
I don't need the output of main just the runtime, saved into a file.







share|improve this question

























    up vote
    0
    down vote

    favorite












    I want to run an executable main and redirect all outputs to /dev/null, meanwhile I measure its runtime with time and write the results to runtime.out. Since the task is long I also have to run the whole thing with nohup.

    I tried the following:

    nohup time ./main &> /dev/null &> runtime.out &

    This just outputs everything to runtime.out.
    I don't need the output of main just the runtime, saved into a file.







    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I want to run an executable main and redirect all outputs to /dev/null, meanwhile I measure its runtime with time and write the results to runtime.out. Since the task is long I also have to run the whole thing with nohup.

      I tried the following:

      nohup time ./main &> /dev/null &> runtime.out &

      This just outputs everything to runtime.out.
      I don't need the output of main just the runtime, saved into a file.







      share|improve this question













      I want to run an executable main and redirect all outputs to /dev/null, meanwhile I measure its runtime with time and write the results to runtime.out. Since the task is long I also have to run the whole thing with nohup.

      I tried the following:

      nohup time ./main &> /dev/null &> runtime.out &

      This just outputs everything to runtime.out.
      I don't need the output of main just the runtime, saved into a file.









      share|improve this question












      share|improve this question




      share|improve this question








      edited May 10 at 11:08









      Jeff Schaller

      31.1k846105




      31.1k846105









      asked May 9 at 15:18









      D Nagy

      1032




      1032




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          time has something made to be used for this:



          nohup time -o runtime.out ./main &> /dev/null &


          If it was scripted and didn't require a tty, I'd rather use setsid than nohup + &, because it "daemonizes" better, and can still be sent a HUP signal if needed.



          setsid time -o runtime.out ./main </dev/null &>/dev/null


          Also note that here (as in OP's question) time is /usr/bin/time, which has a different output format than bash's builtin time command. It appears that /usr/bin/time --portability gives a similar output if needed.






          share|improve this answer






























            up vote
            1
            down vote













            Through some trial & error and stealing inspiration from bash time with nohup , I came up with the following:



            $ nohup bash -c 'time ./main &> /dev/null' > runtime.out &
            [1] 23178
            nohup: ignoring input and redirecting stderr to stdout
            $
            [1]+ Done nohup bash -c 'time ./main &> /dev/null' > runtime.out
            $ cat runtime.out

            real 0m0.004s
            user 0m0.002s
            sys 0m0.002s


            This will redirect stdout of time to runtime.out, print stdout of nohup to the terminal, and redirect stdout and stderr of main to /dev/null.






            share|improve this answer




























              up vote
              0
              down vote













              This appears to do the right thing:



              $ time > runtime.out nohup ./main &> /dev/null &





              share|improve this answer





















              • When I try this, I see the stdout of time on the terminal and runtime.out is empty. (Where main is a simple shell script with an echo)
                – Kevin Kruse
                May 9 at 16:17










              • Interesting, because when I ran that, I saw no output, and had a runtime.out file with the output of time therein. Redirecting main's output to main.out resulted in the expected two files rightly populated.
                – DopeGhoti
                May 9 at 16:19










              • Strange. Could it be shell differences? I'm using GNU bash, version 4.2.46(2)-release
                – Kevin Kruse
                May 9 at 16:49










              • 4.4.19(1)-release over here. :shrug:
                – DopeGhoti
                May 9 at 16:53










              • sadly this does not do the job.
                – D Nagy
                May 10 at 12:17










              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%2f442805%2fusing-nohup-and-time-with-different-outputs%23new-answer', 'question_page');

              );

              Post as a guest






























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              1
              down vote



              accepted










              time has something made to be used for this:



              nohup time -o runtime.out ./main &> /dev/null &


              If it was scripted and didn't require a tty, I'd rather use setsid than nohup + &, because it "daemonizes" better, and can still be sent a HUP signal if needed.



              setsid time -o runtime.out ./main </dev/null &>/dev/null


              Also note that here (as in OP's question) time is /usr/bin/time, which has a different output format than bash's builtin time command. It appears that /usr/bin/time --portability gives a similar output if needed.






              share|improve this answer



























                up vote
                1
                down vote



                accepted










                time has something made to be used for this:



                nohup time -o runtime.out ./main &> /dev/null &


                If it was scripted and didn't require a tty, I'd rather use setsid than nohup + &, because it "daemonizes" better, and can still be sent a HUP signal if needed.



                setsid time -o runtime.out ./main </dev/null &>/dev/null


                Also note that here (as in OP's question) time is /usr/bin/time, which has a different output format than bash's builtin time command. It appears that /usr/bin/time --portability gives a similar output if needed.






                share|improve this answer

























                  up vote
                  1
                  down vote



                  accepted







                  up vote
                  1
                  down vote



                  accepted






                  time has something made to be used for this:



                  nohup time -o runtime.out ./main &> /dev/null &


                  If it was scripted and didn't require a tty, I'd rather use setsid than nohup + &, because it "daemonizes" better, and can still be sent a HUP signal if needed.



                  setsid time -o runtime.out ./main </dev/null &>/dev/null


                  Also note that here (as in OP's question) time is /usr/bin/time, which has a different output format than bash's builtin time command. It appears that /usr/bin/time --portability gives a similar output if needed.






                  share|improve this answer















                  time has something made to be used for this:



                  nohup time -o runtime.out ./main &> /dev/null &


                  If it was scripted and didn't require a tty, I'd rather use setsid than nohup + &, because it "daemonizes" better, and can still be sent a HUP signal if needed.



                  setsid time -o runtime.out ./main </dev/null &>/dev/null


                  Also note that here (as in OP's question) time is /usr/bin/time, which has a different output format than bash's builtin time command. It appears that /usr/bin/time --portability gives a similar output if needed.







                  share|improve this answer















                  share|improve this answer



                  share|improve this answer








                  edited May 9 at 21:44


























                  answered May 9 at 21:39









                  A.B

                  2,4901315




                  2,4901315






















                      up vote
                      1
                      down vote













                      Through some trial & error and stealing inspiration from bash time with nohup , I came up with the following:



                      $ nohup bash -c 'time ./main &> /dev/null' > runtime.out &
                      [1] 23178
                      nohup: ignoring input and redirecting stderr to stdout
                      $
                      [1]+ Done nohup bash -c 'time ./main &> /dev/null' > runtime.out
                      $ cat runtime.out

                      real 0m0.004s
                      user 0m0.002s
                      sys 0m0.002s


                      This will redirect stdout of time to runtime.out, print stdout of nohup to the terminal, and redirect stdout and stderr of main to /dev/null.






                      share|improve this answer

























                        up vote
                        1
                        down vote













                        Through some trial & error and stealing inspiration from bash time with nohup , I came up with the following:



                        $ nohup bash -c 'time ./main &> /dev/null' > runtime.out &
                        [1] 23178
                        nohup: ignoring input and redirecting stderr to stdout
                        $
                        [1]+ Done nohup bash -c 'time ./main &> /dev/null' > runtime.out
                        $ cat runtime.out

                        real 0m0.004s
                        user 0m0.002s
                        sys 0m0.002s


                        This will redirect stdout of time to runtime.out, print stdout of nohup to the terminal, and redirect stdout and stderr of main to /dev/null.






                        share|improve this answer























                          up vote
                          1
                          down vote










                          up vote
                          1
                          down vote









                          Through some trial & error and stealing inspiration from bash time with nohup , I came up with the following:



                          $ nohup bash -c 'time ./main &> /dev/null' > runtime.out &
                          [1] 23178
                          nohup: ignoring input and redirecting stderr to stdout
                          $
                          [1]+ Done nohup bash -c 'time ./main &> /dev/null' > runtime.out
                          $ cat runtime.out

                          real 0m0.004s
                          user 0m0.002s
                          sys 0m0.002s


                          This will redirect stdout of time to runtime.out, print stdout of nohup to the terminal, and redirect stdout and stderr of main to /dev/null.






                          share|improve this answer













                          Through some trial & error and stealing inspiration from bash time with nohup , I came up with the following:



                          $ nohup bash -c 'time ./main &> /dev/null' > runtime.out &
                          [1] 23178
                          nohup: ignoring input and redirecting stderr to stdout
                          $
                          [1]+ Done nohup bash -c 'time ./main &> /dev/null' > runtime.out
                          $ cat runtime.out

                          real 0m0.004s
                          user 0m0.002s
                          sys 0m0.002s


                          This will redirect stdout of time to runtime.out, print stdout of nohup to the terminal, and redirect stdout and stderr of main to /dev/null.







                          share|improve this answer













                          share|improve this answer



                          share|improve this answer











                          answered May 9 at 16:40









                          Kevin Kruse

                          18610




                          18610




















                              up vote
                              0
                              down vote













                              This appears to do the right thing:



                              $ time > runtime.out nohup ./main &> /dev/null &





                              share|improve this answer





















                              • When I try this, I see the stdout of time on the terminal and runtime.out is empty. (Where main is a simple shell script with an echo)
                                – Kevin Kruse
                                May 9 at 16:17










                              • Interesting, because when I ran that, I saw no output, and had a runtime.out file with the output of time therein. Redirecting main's output to main.out resulted in the expected two files rightly populated.
                                – DopeGhoti
                                May 9 at 16:19










                              • Strange. Could it be shell differences? I'm using GNU bash, version 4.2.46(2)-release
                                – Kevin Kruse
                                May 9 at 16:49










                              • 4.4.19(1)-release over here. :shrug:
                                – DopeGhoti
                                May 9 at 16:53










                              • sadly this does not do the job.
                                – D Nagy
                                May 10 at 12:17














                              up vote
                              0
                              down vote













                              This appears to do the right thing:



                              $ time > runtime.out nohup ./main &> /dev/null &





                              share|improve this answer





















                              • When I try this, I see the stdout of time on the terminal and runtime.out is empty. (Where main is a simple shell script with an echo)
                                – Kevin Kruse
                                May 9 at 16:17










                              • Interesting, because when I ran that, I saw no output, and had a runtime.out file with the output of time therein. Redirecting main's output to main.out resulted in the expected two files rightly populated.
                                – DopeGhoti
                                May 9 at 16:19










                              • Strange. Could it be shell differences? I'm using GNU bash, version 4.2.46(2)-release
                                – Kevin Kruse
                                May 9 at 16:49










                              • 4.4.19(1)-release over here. :shrug:
                                – DopeGhoti
                                May 9 at 16:53










                              • sadly this does not do the job.
                                – D Nagy
                                May 10 at 12:17












                              up vote
                              0
                              down vote










                              up vote
                              0
                              down vote









                              This appears to do the right thing:



                              $ time > runtime.out nohup ./main &> /dev/null &





                              share|improve this answer













                              This appears to do the right thing:



                              $ time > runtime.out nohup ./main &> /dev/null &






                              share|improve this answer













                              share|improve this answer



                              share|improve this answer











                              answered May 9 at 16:07









                              DopeGhoti

                              40k54779




                              40k54779











                              • When I try this, I see the stdout of time on the terminal and runtime.out is empty. (Where main is a simple shell script with an echo)
                                – Kevin Kruse
                                May 9 at 16:17










                              • Interesting, because when I ran that, I saw no output, and had a runtime.out file with the output of time therein. Redirecting main's output to main.out resulted in the expected two files rightly populated.
                                – DopeGhoti
                                May 9 at 16:19










                              • Strange. Could it be shell differences? I'm using GNU bash, version 4.2.46(2)-release
                                – Kevin Kruse
                                May 9 at 16:49










                              • 4.4.19(1)-release over here. :shrug:
                                – DopeGhoti
                                May 9 at 16:53










                              • sadly this does not do the job.
                                – D Nagy
                                May 10 at 12:17
















                              • When I try this, I see the stdout of time on the terminal and runtime.out is empty. (Where main is a simple shell script with an echo)
                                – Kevin Kruse
                                May 9 at 16:17










                              • Interesting, because when I ran that, I saw no output, and had a runtime.out file with the output of time therein. Redirecting main's output to main.out resulted in the expected two files rightly populated.
                                – DopeGhoti
                                May 9 at 16:19










                              • Strange. Could it be shell differences? I'm using GNU bash, version 4.2.46(2)-release
                                – Kevin Kruse
                                May 9 at 16:49










                              • 4.4.19(1)-release over here. :shrug:
                                – DopeGhoti
                                May 9 at 16:53










                              • sadly this does not do the job.
                                – D Nagy
                                May 10 at 12:17















                              When I try this, I see the stdout of time on the terminal and runtime.out is empty. (Where main is a simple shell script with an echo)
                              – Kevin Kruse
                              May 9 at 16:17




                              When I try this, I see the stdout of time on the terminal and runtime.out is empty. (Where main is a simple shell script with an echo)
                              – Kevin Kruse
                              May 9 at 16:17












                              Interesting, because when I ran that, I saw no output, and had a runtime.out file with the output of time therein. Redirecting main's output to main.out resulted in the expected two files rightly populated.
                              – DopeGhoti
                              May 9 at 16:19




                              Interesting, because when I ran that, I saw no output, and had a runtime.out file with the output of time therein. Redirecting main's output to main.out resulted in the expected two files rightly populated.
                              – DopeGhoti
                              May 9 at 16:19












                              Strange. Could it be shell differences? I'm using GNU bash, version 4.2.46(2)-release
                              – Kevin Kruse
                              May 9 at 16:49




                              Strange. Could it be shell differences? I'm using GNU bash, version 4.2.46(2)-release
                              – Kevin Kruse
                              May 9 at 16:49












                              4.4.19(1)-release over here. :shrug:
                              – DopeGhoti
                              May 9 at 16:53




                              4.4.19(1)-release over here. :shrug:
                              – DopeGhoti
                              May 9 at 16:53












                              sadly this does not do the job.
                              – D Nagy
                              May 10 at 12:17




                              sadly this does not do the job.
                              – D Nagy
                              May 10 at 12:17












                               

                              draft saved


                              draft discarded


























                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f442805%2fusing-nohup-and-time-with-different-outputs%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Popular posts from this blog

                              Peggy Mitchell

                              Palaiologos

                              The Forum (Inglewood, California)