linux – 从后台进程重定向stdout和stderr

我有一个名为foo的脚本,它运行程序a.exe并将计时统计信息发送到文件time.log

#!/bin/bash
date 1>> time.log
(time ./a.exe) 2>> time.log

如果我在终端的后台运行脚本并保持shell打开直到a.exe完成,但是如果我在后台运行脚本并退出终端(a.exe需要很长时间才能运行)

foo & 
exit

当我回来时,a.exe已经执行但时间统计信息没有出现在我的日志文件中.有人知道为什么吗?在我关闭父shell之后有没有办法获取时序统计信息?

谢谢

解决方法:

nohup foo &

当你退出shell时,它会向所有子进程发送一个SIGHUP信号,默认情况下会杀死它们.如果您希望进程在父shell退出时继续执行,那么您需要让它忽略SIGHUP.

NAME

nohup — invoke a command immune to hangups

SYNOPSIS

06001

DESCRIPTION

The nohup utility invokes command with its arguments and at this time sets the signal SIGHUP to be ignored. If the standard output is a terminal, the standard output is appended to the file nohup.out in the current directory. If standard error is a terminal, it is directed to the same place as the standard output.

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...