Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unix 如何在不获取nohup.out的情况下使用nohup命令?_Unix_Jobs - Fatal编程技术网

Unix 如何在不获取nohup.out的情况下使用nohup命令?

Unix 如何在不获取nohup.out的情况下使用nohup命令?,unix,jobs,Unix,Jobs,我对nohup命令有问题 当我运行我的作业时,我有很多数据。输出nohup.out变得太大,我的进程减慢。如何在不获取nohup.out的情况下运行此命令?您可能需要使用。您可以像nohup一样使用它,但除非您告诉它,否则它不会生成输出日志。以下是手册页: NAME detach - run a command after detaching from the terminal SYNOPSIS detach [options] [--] command [args

我对nohup命令有问题

当我运行我的作业时,我有很多数据。输出nohup.out变得太大,我的进程减慢。如何在不获取nohup.out的情况下运行此命令?

您可能需要使用。您可以像
nohup
一样使用它,但除非您告诉它,否则它不会生成输出日志。以下是手册页:

NAME
       detach - run a command after detaching from the terminal

SYNOPSIS
       detach [options] [--] command [args]

       Forks  a  new process, detaches is from the terminal, and executes com‐
       mand with the specified arguments.

OPTIONS
       detach recognizes a couple of options, which are discussed below.   The
       special  option -- is used to signal that the rest of the arguments are
       the command and args to be passed to it.

       -e file
              Connect file to the standard error of the command.

       -f     Run in the foreground (do not fork).

       -i file
              Connect file to the standard input of the command.

       -o file
              Connect file to the standard output of the command.

       -p file
              Write the pid of the detached process to file.

EXAMPLE
       detach xterm

       Start an xterm that will not be closed when the current shell exits.

AUTHOR
       detach was written by Robbert Haarman.  See  http://inglorion.net/  for
       contact information.
注:我与该计划的作者没有任何联系。我只是一个满意的程序用户。

您可能想使用。您可以像
nohup
一样使用它,但除非您告诉它,否则它不会生成输出日志。以下是手册页:

NAME
       detach - run a command after detaching from the terminal

SYNOPSIS
       detach [options] [--] command [args]

       Forks  a  new process, detaches is from the terminal, and executes com‐
       mand with the specified arguments.

OPTIONS
       detach recognizes a couple of options, which are discussed below.   The
       special  option -- is used to signal that the rest of the arguments are
       the command and args to be passed to it.

       -e file
              Connect file to the standard error of the command.

       -f     Run in the foreground (do not fork).

       -i file
              Connect file to the standard input of the command.

       -o file
              Connect file to the standard output of the command.

       -p file
              Write the pid of the detached process to file.

EXAMPLE
       detach xterm

       Start an xterm that will not be closed when the current shell exits.

AUTHOR
       detach was written by Robbert Haarman.  See  http://inglorion.net/  for
       contact information.

注:我与该计划的作者没有任何联系。我只是一个满意的程序用户。

您是否尝试重定向所有三个I/O流:

nohup ./yourprogram > foo.out 2> foo.err < /dev/null &
nohup./yourprogram>foo.out 2>foo.err
您是否尝试重定向所有三个I/O流:

nohup ./yourprogram > foo.out 2> foo.err < /dev/null &
nohup./yourprogram>foo.out 2>foo.err
如果输出将转到终端,则
nohup
命令仅写入
nohup.out
。如果您已将命令的输出重定向到其他地方(包括
/dev/null
),则它将转到该位置

 nohup command >/dev/null 2>&1   # doesn't create nohup.out
如果您使用的是
nohup
,这可能意味着您希望在后台运行该命令,方法是在整个过程的末尾放置另一个
&

 nohup command >/dev/null 2>&1 & # runs in background, still doesn't create nohup.out
在Linux上,使用
nohup
运行作业也会自动关闭其输入。在其他系统上,尤其是BSD和macOS,情况并非如此,因此在后台运行时,可能需要手动关闭输入。虽然关闭输入对创建或不创建
nohup.out
没有影响,但它避免了另一个问题:如果后台进程试图从标准输入读取任何内容,它将暂停,等待您将其返回前台并键入内容。因此,超安全版本如下所示:

nohup command </dev/null >/dev/null 2>&1 & # completely detached from terminal 
nohup命令/dev/null 2>&1&#与终端完全分离
但是,请注意,这不会阻止命令直接访问终端,也不会将其从shell的进程组中删除。如果要执行后一种操作,并且正在运行bash、ksh或zsh,则可以通过运行
disown
,而不使用参数作为下一个命令来执行。这将意味着后台进程不再与shell“作业”关联,并且不会有任何信号从shell转发给它。(注意区别:一个
disown
ed进程没有收到由其父shell自动转发给它的信号,但是如果没有
nohup
,它仍然会收到一个通过其他方式发送的
HUP
信号,例如手动
kill
命令。
nohup
ed进程忽略任何和所有
HUP
信号,no无论如何发送。)

说明:

在Unixy系统中,每个输入源或输出目标都有一个与其相关联的数字,称为“文件描述符”,简称“fd”。每个正在运行的程序(“进程”)都有自己的一组,当一个新进程启动时,其中三个程序已经打开:“标准输入”(fd 0)为进程的读取打开,而“标准输出”(fd 1)和“标准错误”(fd 2)为进程的写入打开。如果您只是在终端窗口中运行命令,那么默认情况下,您键入的任何内容都将转到其标准输入,而其标准输出和标准错误都将发送到该窗口

但是,在启动命令之前,您可以要求shell更改这些文件描述符的任何或所有指向的位置;这就是重定向(
)和管道(
|
)操作符所做的

管道是其中最简单的
command1 | command2
安排
command1
的标准输出直接输入到
command2
的标准输入中。这是一种非常方便的安排,导致UNIX工具中出现了一种特殊的设计模式(并解释了标准错误的存在,该错误允许程序向用户发送消息,即使其输出将进入管道中的下一个程序)。但您只能将标准输出管道化为标准输入;你不能发送任何其他文件描述符到管道没有一些杂耍

重定向操作符更友好,因为它们允许您指定要重定向的文件描述符。因此
0>logfile
在名为
logfile
的文件末尾追加标准错误。如果未指定数字,则输入重定向默认为fd 0(

此外,您还可以将文件描述符组合在一起:
2>&1
表示“在标准输出的任何地方发送标准错误”。这意味着您将获得一个包含标准输出和标准错误的输出流,并且无法再将它们分开,但这也意味着您可以在管道中包含标准错误

因此序列
/dev/null 2>&1
意味着“将标准输出发送到
/dev/null
”(这是一种特殊的设备,它可以丢弃您向它写入的任何内容),然后将标准错误发送到标准输出的任何地方”(我们刚刚确定的是
/dev/null
)。基本上,“扔掉这个命令写入任何一个文件描述符的内容”

nohup
检测到它的标准错误和输出都没有连接到终端时,它不必费心创建
nohup.out
,而是假设输出已经重定向到用户希望它去的地方


/dev/null
设备也可以用于输入;如果使用
/dev/null运行命令,
nohup
命令仅写入
nohup.out
,否则输出将转到终端。如果你有重定向
nohup <your command> & >  <outputfile> 2>&1 &
./Runjob.sh > sparkConcuurent.out 2>&1
nohup command |tee &
#!/bin/bash
echo "Hello. This is a proper command"
junk_errorcommand
./zz.sh
zz.sh > zfile.txt
zz.sh 1> zfile.txt
zz.sh 2> zfile.txt
zz.sh 1> zfile.txt 2>&1
nohup zz.sh 1> zfile.txt 2>&1&