linux nohup命令
2016-06-28 11:35
555 查看
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 参数指定的命令不可调用。如果标准错误是一个终端,那么把指定的命令写给标准错误的所有输出作为标准输出重定向到相同的文件描述符。
=======测试
指定输出到lxjtest.log。如果不指定,则输出到nohup.out文件
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命令)
用途:不挂断地运行命令。如果你正在执行一个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 & [1] 2547 [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命令一直在执行 64 bytes from 127.0.0.1: icmp_seq=21 ttl=64 time=0.077 ms 64 bytes from 127.0.0.1: icmp_seq=22 ttl=64 time=0.044 ms 64 bytes from 127.0.0.1: icmp_seq=23 ttl=64 time=0.129 ms 64 bytes from 127.0.0.1: icmp_seq=24 ttl=64 time=0.084 ms 64 bytes from 127.0.0.1: icmp_seq=25 ttl=64 time=0.085 ms 64 bytes from 127.0.0.1: icmp_seq=26 ttl=64 time=0.085 ms 64 bytes from 127.0.0.1: icmp_seq=27 ttl=64 time=0.079 ms 64 bytes from 127.0.0.1: icmp_seq=28 ttl=64 time=0.078 ms 64 bytes from 127.0.0.1: icmp_seq=29 ttl=64 time=0.078 ms 64 bytes from 127.0.0.1: icmp_seq=30 ttl=64 time=0.083 ms 64 bytes from 127.0.0.1: icmp_seq=31 ttl=64 time=0.043 ms 64 bytes from 127.0.0.1: icmp_seq=32 ttl=64 time=0.084 ms ^C [root@rhel7 tmp]#
指定输出到lxjtest.log。如果不指定,则输出到nohup.out文件
[root@rhel7 tmp]# nohup ping 127.0.0.1 >lxjtest.log & [1] 2641 [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) 56(84) bytes of data. 64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.039 ms 64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.073 ms 64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.043 ms 64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.043 ms 64 bytes from 127.0.0.1: icmp_seq=5 ttl=64 time=0.044 ms 64 bytes from 127.0.0.1: icmp_seq=6 ttl=64 time=0.044 ms 64 bytes from 127.0.0.1: icmp_seq=7 ttl=64 time=0.043 ms 64 bytes from 127.0.0.1: icmp_seq=8 ttl=64 time=0.079 ms 64 bytes from 127.0.0.1: icmp_seq=9 ttl=64 time=0.079 ms 64 bytes from 127.0.0.1: icmp_seq=10 ttl=64 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 & [1] 2649 [root@rhel7 tmp]# jobs [1]+ Running ping 192.168.1.111 > lxjtest2.log & [root@rhel7 tmp]#
相关文章推荐
- Source order for linux
- linux小知识之目录卸载
- 在centos6.5-64bit上安装wxHexEditor,以查看编译二进制文件
- CentOS 安装配置subversion
- Linux/ubuntu下安装Chrome
- Centos 7 ssh秘钥认证(无需密码ssh)
- Hadoop集群安装配置教程_Hadoop2.6.0_Ubuntu/CentOS
- 虚拟机中实现Linux与Windows之间的文件传输
- Linux2.6内核驱动移植变化参考
- linux 策略路由实例解析
- Linux下文件内容查阅命令
- linux 定时备份mysql数据库
- SCp上传文件到阿里云服务器
- 在Linux环境下mysql的root密码忘记解决方法,修改root密码
- linux内核SPI总线驱动分析(一)
- Unix哲学
- 编译Linux内核4.6.3使其支持NTFS文件系统
- Linux 常用命令
- (5)linux下编译安装配置php
- (4)linux下安装配置Mysql