什么为&lt;的/ dev / null的在bash? [英] What is </dev/null in bash?
问题描述
在bash中,标准(1)和误差(2)输出可被重新路由,并与丢弃
In bash, standard (1) and error (2) output can be re-routed and discarded with:
>/dev/null 2>&1
但下面的例子做不同的东西:
But the following example does something different:
nohup myscript.sh >myscript.log 2>&1 </dev/null &
什么是&LT的意义/功能;在上面的例子中的/ dev / null的
?在什么样的脚本场景将是有用的?
What is the meaning/function of </dev/null
in the example above? In what sort of scripting scenario would it be useful?
<一个href=\"http://stackoverflow.com/questions/8122780/exiting-shell-script-with-background-processes\">(Example源)
推荐答案
重定向的/ dev / null的
来标准输入会给出一个直接的 EOF
从该进程的任何read调用。这通常是从一个tty分离的处理有用(这种工艺被称为守护进程)。例如,通过ssh远程启动一个后台进程时,你必须标准输入重定向到prevent过程中等待本地输入。
Redirecting /dev/null
to stdin will give an immediate EOF
to any read call from that process. This is typically useful to detach a process from a tty (such a process is called a daemon). For example, when starting a background process remotely over ssh, you must redirect stdin to prevent the process waiting for local input.
重定向到/ dev / null的另一个原因是prevent标准输入创建一个未使用的文件描述符。这可以最大限度地减少总的打开的文件句柄,当你有很多长时间运行的进程。
Another reason to redirect to /dev/null is to prevent an unused file descriptor being created for stdin. This can minimize the total open file handles when you have many long running processes.
这篇关于什么为&lt;的/ dev / null的在bash?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!