nohup 命令

用途:不挂断地运行命令。如果你正在执行一个job,并且你希望在退出帐户/关闭终端之后继续运行,可以使用nohup命令。nohup就是不挂起的意思( no hang up)。

语法:nohup Command [ Arg … ] [ & ]

描述:nohup 命令运行由 Command 参数和任何相关的 Arg 参数指定的命令,忽略所有挂断(SIGHUP)信号。在注销后使用 nohup 命令运行后台中的程序。要运行后台中的 nohup 命令,添加 & ( 表示”and”的符号)到命令的尾部。

无论是否将 nohup 命令的输出重定向到终端,输出都将附加到当前目录的 nohup.out 文件中。如果当前目录的 nohup.out 文件不可写,输出重定向到 $HOME/nohup.out 文件中。如果没有文件能创建或打开以用于追加,那么 Command 参数指定的命令不可调用。如果标准错误是一个终端,那么把指定的命令写给标准错误的所有输出作为标准输出重定向到相同的文件描述符。

=======测试

[root@rhel7 tmp]# pwd
/tmp
[root@rhel7 tmp]# ls
[root@rhel7 tmp]# nohup ping 127.0.0.1 &
[]
[root@rhel7 tmp]# nohup: ignoring input and appending output to ‘nohup.out’ [root@rhel7 tmp]# ls
nohup.out
[root@rhel7 tmp]# tail -f nohup.out --关闭当前连接,重新再打开一个ssh连接,使用tail -f nohup.out命令可以看到ping命令一直在执行
bytes from 127.0.0.1: icmp_seq= ttl= time=0.077 ms
bytes from 127.0.0.1: icmp_seq= ttl= time=0.044 ms
bytes from 127.0.0.1: icmp_seq= ttl= time=0.129 ms
bytes from 127.0.0.1: icmp_seq= ttl= time=0.084 ms
bytes from 127.0.0.1: icmp_seq= ttl= time=0.085 ms
bytes from 127.0.0.1: icmp_seq= ttl= time=0.085 ms
bytes from 127.0.0.1: icmp_seq= ttl= time=0.079 ms
bytes from 127.0.0.1: icmp_seq= ttl= time=0.078 ms
bytes from 127.0.0.1: icmp_seq= ttl= time=0.078 ms
bytes from 127.0.0.1: icmp_seq= ttl= time=0.083 ms
bytes from 127.0.0.1: icmp_seq= ttl= time=0.043 ms
bytes from 127.0.0.1: icmp_seq= ttl= time=0.084 ms
^C
[root@rhel7 tmp]#

指定输出到lxjtest.log。如果不指定,则输出到nohup.out文件

[root@rhel7 tmp]# nohup ping 127.0.0.1 >lxjtest.log &
[]
[root@rhel7 tmp]# nohup: ignoring input and redirecting stderr to stdout [root@rhel7 tmp]# ls
lxjtest.log nohup.out
[root@rhel7 tmp]# tail -f lxjtest.log
PING 127.0.0.1 (127.0.0.1) () bytes of data.
bytes from 127.0.0.1: icmp_seq= ttl= time=0.039 ms
bytes from 127.0.0.1: icmp_seq= ttl= time=0.073 ms
bytes from 127.0.0.1: icmp_seq= ttl= time=0.043 ms
bytes from 127.0.0.1: icmp_seq= ttl= time=0.043 ms
bytes from 127.0.0.1: icmp_seq= ttl= time=0.044 ms
bytes from 127.0.0.1: icmp_seq= ttl= time=0.044 ms
bytes from 127.0.0.1: icmp_seq= ttl= time=0.043 ms
bytes from 127.0.0.1: icmp_seq= ttl= time=0.079 ms
bytes from 127.0.0.1: icmp_seq= ttl= time=0.079 ms
bytes from 127.0.0.1: icmp_seq= ttl= time=0.086 ms
^C
[root@rhel7 tmp]#

In earlier versions of the bash shell, background processes were also killed when the shell they were started from was terminated. To prevent that, the process could be started with the  nohup  command in front of it. Using  nohup  for this purpose is no longer needed in RHEL 7. (RHEL7版本可以不使用nohup命令)

[root@rhel7 tmp]# ping 192.168.1.111 > lxjtest2.log &
[]
[root@rhel7 tmp]# jobs
[]+ Running ping 192.168.1.111 > lxjtest2.log &
[root@rhel7 tmp]#

linux nohup命令的更多相关文章

  1. Linux nohup 命令

    Linux nohup 命令 如果你正在运行一个进程,而且你觉得在退出帐户时该进程还不会结束,那么可以使用nohup命令.该命令可以在你退出帐户之后继续运行相应的进程.nohup就是不挂起的意思(no ...

  2. linux–nohup命令(转)

    在应用Unix/Linux时,我们一般想让某个程序在后台运行,于是我们将常会用 & 在程序结尾来让程序自动运行.比如我们要运行mysql在后台: /usr/local/mysql/bin/my ...

  3. LINUX nohup命令输入输出深浅进出

    无论是否将 nohup命令的输出重定向到终端,输出都将附加到当前目录的 nohup.out 文件中.如果当前目录的 nohup.out 文件不可写,输出重定向到 $HOME/nohup.out 文件中 ...

  4. Linux nohup命令详解

    nohup命令及其输出文件                                                                                       ...

  5. linux nohup命令实现退出终端后程序继续后台运行

    Unix/Linux下一般想让某个程序在后台运行,很多都是使用&在程序结尾来让程序自动运行:但如果要想在退出终端后,程序依然还在后台运行,则要用nohup与&组合来实现. nohup ...

  6. Linux nohup命令应用简介--让Linux的进程不受终端影响

    nohup命令应用简介--让Linux的进程不受终端影响 by:授客 QQ:1033553122   #开启ping进程 [root@localhost ~]# ping localhost & ...

  7. linux nohup命令使程序在后台运行的方法

    在linux操作系统中从后台一直运行某个程序的方法,就是使用nohup命令了. Unix/Linux下一般比如想让某个程序在后台运行,很多都是使用 & 在程序结尾来让程序自动运行. 比如要运行 ...

  8. Linux nohup命令详解,终端关闭程序依然可以在执行!

    大家好,我是良许. 在工作中,我们很经常跑一个很重要的程序,有时候这个程序需要跑好几个小时,甚至需要几天,这个时候如果我们退出终端,或者网络不好连接中断,那么程序就会被中止.而这个情况肯定不是我们想看 ...

  9. Linux Shell nohup命令用法

    linux的nohup命令的用法.   在应用Unix/Linux时,我们一般想让某个程序在后台运行,于是我们将常会用 & 在程序结尾来让程序自动运行.比如我们要运行mysql在后台: /us ...

随机推荐

  1. 如何让Hadoop运行得更快一些

    在数据处理方面,我们发现数据输入速度一般要比的数据处理速度快很多,这种现象在大多数据领域尤为明显.随着数据不断膨胀,相应的响应时间自然要有所增加,数据处理的复杂度也在不断提高.作为一个开发者,我们自然 ...

  2. OpenGL旋转平移 变换

    #include<gl/glut.h> #include<gl/GL.h> #include<gl/GLU.h> #include<math.h> #i ...

  3. 打包静默安装参数(nsis,msi,InstallShield,InnoSetup)[转]

    有时我们在安装程序的时候,希望是静默安装的,不显示下一步下一步,这编访问来教大家如何来操作,现在常用的制作安装程序的软件有,  Microsoft Windows Installer  , Windo ...

  4. JQUERY1.9学习笔记 之内容过滤器(四) parent选择器

    描述:选择至少包含一个子节点的元素(一个标签或是文本). 例:找出所有有子元素的td标签,包含文本. <!doctype html><html lang="en" ...

  5. C++ 性能剖析 (一)

    C++ 性能剖析 (一) 性能问题也不是仅仅用“技术”可以解决的,它往往是架构,测试,假设等综合难题.不过,对于一个工程师来说,必须从小做起,把一些“明显”的小问题解决.否则的话积小成多,千里堤坝,溃 ...

  6. 代码发布架构方案(SVN)

    问题: 安装优化软件环境nginx,lvs  程序代码(不断更新) 配置更新(不断变更) 1.SVN介绍 1.1 什么是SVN(Subversion)?         SVN(Subversion) ...

  7. Aptana Studio 快捷键

    窗口 Ctrl+ Shift +L 调出快捷键提示 Ctrl+ W 关闭当前标签窗口 Ctrl+ Shift + W 关闭当前标签窗口 Ctrl+ F6 (或者是Aptana的Ctrl+Tab )下一 ...

  8. .net FrameWork4.0安装未成功

    安装了一上午的.net framework 4.0,各种失败,查了好多答案,各种不靠谱,最后终于找到答案了 和Windows Update有关系,给目录名重命名一下再次安装,即安装成功了! 下载地址: ...

  9. Acunetix Web Vulnerability Scanner Python辅助脚本

    WvsScannerQueue.pyVersion: Python 2.7.* Acunetix Web Vulnerability Scanner 辅助Python脚本的第一个版本.功能:扫描URL ...

  10. osvdb

    http://www.91ri.org/3117.html http://linux.cn/article-5332-1-rss.html http://www.freebuf.com/article ...