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. 浅谈C++ 异常处理的语义和性能

    异常处理是个十分深奥的主题,这里只是浅论其对C++性能的影响. 在VC++中,有多个异常处理模式,三个最重要: No exception handling (无异常处理) C++ only (C++语 ...

  2. 【USACO 3.1.6】邮票

    [描述] 已知一个N枚邮票的面值集合(如,{1分,3分})和一个上限K ——表示信封上能够贴K张邮票.计算从1到M的最大连续可贴出的邮资. 例如,假设有1分和3分的邮票:你最多可以贴5张邮票.很容易贴 ...

  3. highCharts 图表统计控件使用方法

    1.首先引用js文件 在引用上面文件时,保证已经引用了jquery.js文件.且位置在上面两个文件之前. 2. <div id="container" style=" ...

  4. PAT - IO-01. 表格输出(5)

    题目: 本题要求编写程序,按照规定格式输出表格. 输入格式: 本题目没有输入. 输出格式: 要求严格按照给出的格式输出下列表格: ----------------------------------- ...

  5. Centos 6安装python3.5

    安装python3.5 安装步骤如下 :1 准备编译环境(环境如果不对的话,可能遇到各种问题,比如wget无法下载https链接的文件) yum groupinstall 'Development T ...

  6. Windows下Apache部署Django过程记录

    Win7/Apache/Python2.7/Django1.9部署Web   环境: Windows7 Apache httpd-2.4.16-win64-VC14 Python2.7.11 Djan ...

  7. MVC中的路由

    authour: chenboyi updatetime: 2015-05-02 16:10:04 friendly link:   目录 1,思维导图 2,MVC处理机制简图(讲解路由解析) 3,默 ...

  8. 在centos集成服务器上安装imap扩展

    yum install libc-client-devel.x86_64(如果不行就yum install libc-client-devel)ln -s /usr/lib64/libc-client ...

  9. 『在线工具』 基于 xsser.me 源码 + BootStrap 前端 的 XSS 平台

    乌云社区上一个小伙伴的对xsser.me 的源码做了 BS 的优化,本人已经搭建好,提供给大家免费使用,大牛求绕过,多谢. 地址: http://xss.evilclay.com (目前开放注册,不需 ...

  10. 转:更改 centos yum 源

    centos下可以通过yum很方便快捷的安装所需的软件和库,如果yum的源不好,安装速度会非常慢,centos默认官方源似乎都是国外的,所以速度无法保证,我一直使用163的源,感觉速度不错.下面就说说 ...