Using nohup and time with different outputs

Clash 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.
bash io-redirection executable time nohup
add a comment |Â
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.
bash io-redirection executable time nohup
add a comment |Â
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.
bash io-redirection executable time nohup
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.
bash io-redirection executable time nohup
edited May 10 at 11:08
Jeff Schaller
31.1k846105
31.1k846105
asked May 9 at 15:18
D Nagy
1032
1032
add a comment |Â
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
up vote
0
down vote
This appears to do the right thing:
$ time > runtime.out nohup ./main &> /dev/null &
When I try this, I see thestdoutoftimeon the terminal andruntime.outis empty. (Wheremainis a simple shell script with anecho)
â Kevin Kruse
May 9 at 16:17
Interesting, because when I ran that, I saw no output, and had aruntime.outfile with the output oftimetherein. Redirectingmain's output tomain.outresulted in the expected two files rightly populated.
â DopeGhoti
May 9 at 16:19
Strange. Could it be shell differences? I'm usingGNU bash, version 4.2.46(2)-release
â Kevin Kruse
May 9 at 16:49
4.4.19(1)-releaseover here. :shrug:
â DopeGhoti
May 9 at 16:53
sadly this does not do the job.
â D Nagy
May 10 at 12:17
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
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.
edited May 9 at 21:44
answered May 9 at 21:39
A.B
2,4901315
2,4901315
add a comment |Â
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
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.
answered May 9 at 16:40
Kevin Kruse
18610
18610
add a comment |Â
add a comment |Â
up vote
0
down vote
This appears to do the right thing:
$ time > runtime.out nohup ./main &> /dev/null &
When I try this, I see thestdoutoftimeon the terminal andruntime.outis empty. (Wheremainis a simple shell script with anecho)
â Kevin Kruse
May 9 at 16:17
Interesting, because when I ran that, I saw no output, and had aruntime.outfile with the output oftimetherein. Redirectingmain's output tomain.outresulted in the expected two files rightly populated.
â DopeGhoti
May 9 at 16:19
Strange. Could it be shell differences? I'm usingGNU bash, version 4.2.46(2)-release
â Kevin Kruse
May 9 at 16:49
4.4.19(1)-releaseover here. :shrug:
â DopeGhoti
May 9 at 16:53
sadly this does not do the job.
â D Nagy
May 10 at 12:17
add a comment |Â
up vote
0
down vote
This appears to do the right thing:
$ time > runtime.out nohup ./main &> /dev/null &
When I try this, I see thestdoutoftimeon the terminal andruntime.outis empty. (Wheremainis a simple shell script with anecho)
â Kevin Kruse
May 9 at 16:17
Interesting, because when I ran that, I saw no output, and had aruntime.outfile with the output oftimetherein. Redirectingmain's output tomain.outresulted in the expected two files rightly populated.
â DopeGhoti
May 9 at 16:19
Strange. Could it be shell differences? I'm usingGNU bash, version 4.2.46(2)-release
â Kevin Kruse
May 9 at 16:49
4.4.19(1)-releaseover here. :shrug:
â DopeGhoti
May 9 at 16:53
sadly this does not do the job.
â D Nagy
May 10 at 12:17
add a comment |Â
up vote
0
down vote
up vote
0
down vote
This appears to do the right thing:
$ time > runtime.out nohup ./main &> /dev/null &
This appears to do the right thing:
$ time > runtime.out nohup ./main &> /dev/null &
answered May 9 at 16:07
DopeGhoti
40k54779
40k54779
When I try this, I see thestdoutoftimeon the terminal andruntime.outis empty. (Wheremainis a simple shell script with anecho)
â Kevin Kruse
May 9 at 16:17
Interesting, because when I ran that, I saw no output, and had aruntime.outfile with the output oftimetherein. Redirectingmain's output tomain.outresulted in the expected two files rightly populated.
â DopeGhoti
May 9 at 16:19
Strange. Could it be shell differences? I'm usingGNU bash, version 4.2.46(2)-release
â Kevin Kruse
May 9 at 16:49
4.4.19(1)-releaseover here. :shrug:
â DopeGhoti
May 9 at 16:53
sadly this does not do the job.
â D Nagy
May 10 at 12:17
add a comment |Â
When I try this, I see thestdoutoftimeon the terminal andruntime.outis empty. (Wheremainis a simple shell script with anecho)
â Kevin Kruse
May 9 at 16:17
Interesting, because when I ran that, I saw no output, and had aruntime.outfile with the output oftimetherein. Redirectingmain's output tomain.outresulted in the expected two files rightly populated.
â DopeGhoti
May 9 at 16:19
Strange. Could it be shell differences? I'm usingGNU bash, version 4.2.46(2)-release
â Kevin Kruse
May 9 at 16:49
4.4.19(1)-releaseover 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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password