zoukankan      html  css  js  c++  java
  • 9.10 nohup:用户退出系统进程继续工作

    nohup命令

      可以将程序以忽略挂起信号的方式运行起来,被运行程序的输出信息将不会显示到终端。
           无论是否将nohup命令的输出重定向到终端,输出都将写入到当前目录的nohup.out文件中。如果当前目录的nohup.out文件不可写,则输出重定向到$HOME/nohup.out文件中。

    让执行的命令在当前会话终止后继续保持运行

        正常情况下,如果用户退出登录或会话终止,则用户正在执行并可持续一段时间的命令(非守护进程)将自动终止。使用nohup命令可以实现在用户退出或当前会话终止后继续保持运行,具体的例子如下:
    [root@cs6 ~]# nohup ping g.cn
    nohup: 忽略输入并把输出追加到"nohup.out"
    #<==当前终端已经hang住,此时强制关闭当前终端(例如关闭该标签或者Ss日客户端工具),这个ping命令依然会在后台运行。
    # 但是Ctrl + C 会退出命令执行
     
    [root@cs6 ~]# ps -ef|grep ping
    root       1818      1  0 19:19 ?        00:00:00 ping g.cn
    root       1820   1797  0 19:19 pts/1    00:00:00 grep ping
     
    [root@cs6 ~]# tail -f nohup.out
    64 bytes from 203.208.40.79: icmp_seq=97 ttl=128 time=42.2 ms
    64 bytes from 203.208.40.79: icmp_seq=98 ttl=128 time=42.7 ms
    64 bytes from 203.208.40.79: icmp_seq=99 ttl=128 time=42.7 ms
    64 bytes from 203.208.40.79: icmp_seq=100 ttl=128 time=42.7 ms
    64 bytes from 203.208.40.79: icmp_seq=101 ttl=128 time=42.6 ms
    64 bytes from 203.208.40.79: icmp_seq=102 ttl=128 time=42.4 ms
    64 bytes from 203.208.40.79: icmp_seq=103 ttl=128 time=43.0 ms
    64 bytes from 203.208.40.79: icmp_seq=104 ttl=128 time=50.7 ms
    64 bytes from 203.208.40.79: icmp_seq=105 ttl=128 time=42.9 ms
    64 bytes from 203.208.40.79: icmp_seq=106 ttl=128 time=43.0 ms
     
    在工作中我们一般会配合&符运行nohup命令,让程序直接在后台运行:
     
    [root@cs6 ~]# nohup ping g.cn &
    [1] 1855
    [root@cs6 ~]# nohup: 忽略输入并把输出追加到"nohup.out"
     
    [root@cs6 ~]# tail -f nohup.out
    64 bytes from 203.208.40.95: icmp_seq=8 ttl=128 time=42.1 ms
    64 bytes from 203.208.40.95: icmp_seq=9 ttl=128 time=43.3 ms
    64 bytes from 203.208.40.95: icmp_seq=10 ttl=128 time=44.1 ms
    64 bytes from 203.208.40.95: icmp_seq=11 ttl=128 time=42.5 ms
    64 bytes from 203.208.40.95: icmp_seq=12 ttl=128 time=42.9 ms
    64 bytes from 203.208.40.95: icmp_seq=13 ttl=128 time=42.6 ms
    64 bytes from 203.208.40.95: icmp_seq=14 ttl=128 time=42.8 ms
    64 bytes from 203.208.40.95: icmp_seq=15 ttl=128 time=42.8 ms
    64 bytes from 203.208.40.95: icmp_seq=16 ttl=128 time=134 ms
    64 bytes from 203.208.40.95: icmp_seq=17 ttl=128 time=42.8 ms
    64 bytes from 203.208.40.95: icmp_seq=18 ttl=128 time=42.2 ms
    64 bytes from 203.208.40.95: icmp_seq=19 ttl=128 time=43.2 ms
    64 bytes from 203.208.40.95: icmp_seq=20 ttl=128 time=43.7 ms
    64 bytes from 203.208.40.95: icmp_seq=21 ttl=128 time=42.0 ms
    类似功能的命令还有screen和直接使用&符。
  • 相关阅读:
    子类继承父类,必须声明父类的构造函数
    开发识别屏幕方向的应用程序
    PDA智能设备解决方案打包及部署
    Xcode 下cocos-2dx 环境搭建
    PO订单审批拒绝API
    PO订单审批通过API
    Oracle Forms Services Architecture
    《Oracle Applications DBA 基础》- 9
    Useful Articles for the Oracle E-Business Suite Technology Stack for Technical Consultant / DBA [ID
    Understanding and Using HRMS Security in Oracle HRMS
  • 原文地址:https://www.cnblogs.com/wenyule/p/12214057.html
Copyright © 2011-2022 走看看