重定向标准输出和放大器;从后台进程标准错误 [英] Redirecting stdout & stderr from background process

查看:124
本文介绍了重定向标准输出和放大器;从后台进程标准错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

 #!/斌/庆典
日期1 GT;> time.log
(时间./a.exe)2 - ;> time.log

这工作,如果我在终端的后台运行脚本,并保持我的外壳打开,直到完成a.exe的,但如果我在后台运行脚本,然后退出我的终端(A.EXE需要较长的时间来运行)

 富和放大器;
出口

我回来的时候,已经a.exe的执行,但时间统计不会出现在我的日志文件。有谁知道这是为什么?有没有办法让计时统计我已经关闭父后壳?

感谢


解决方案

 的nohup富和放大器;

当你退出你的shell发送SIGHUP信号给所有的子进程,默认情况下杀死他们。如果你想要一个进程继续当父shell退出,那么你需要把它忽略SIGHUP甚至执行


  

NAME


  
  

的nohup - 调用命令不被挂起


  
  

概要

 的nohup实用程序[参数...]


  
  

说明


  
  

的nohup 实用程序将调用其参数此时命令将被忽略的信号SIGHUP。如果标准输出是终端,标准输出追加到当前目录下的nohup.out文件。如果标准错误是一个终端,它是针对同一个地方标准输出。


I have a script called foo that runs the program a.exe and sends the timing statistics to a file, time.log

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

This works if I run the script in the background of my terminal and keep my shell open until a.exe finishes, but if I run the script in the background and exit my terminal (a.exe takes a long time to run)

foo & 
exit

when I come back, a.exe has executed but the time statistics do not appear in my log file. Does anyone know why this is? Is there a way to get the timing statistics after I've closed the parent shell?

thanks

解决方案

nohup foo &

When you exit your shell it sends a SIGHUP signal to all child processes, which by default kills them. If you want a process to continue executing even when the parent shell exits then you need to have it ignore the SIGHUP.

NAME

nohup -- invoke a command immune to hangups

SYNOPSIS

nohup utility [arg ...]

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.

这篇关于重定向标准输出和放大器;从后台进程标准错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆