美文网首页
使程序在Linux下后台运行 (关掉终端继续让程序运行的方法)

使程序在Linux下后台运行 (关掉终端继续让程序运行的方法)

作者: 一掠而过 | 来源:发表于2017-11-28 18:09 被阅读0次

    将程序转入后台运行

    # nohup [执行代码区] &  如下
    nohup ./test.sh &

    终止后台进程, 首先查找进程

    #ps -ef | grep [关键字]  如下:
    ps -ef | grep test.sh

    ####################################
    root 847 1 0 11:47 ? 00:00:02 /usr/bin/python -Es /usr/sbin/tuned -l -P
    root 28326 28210 0 18:05 pts/0 00:00:00 grep --color=auto py

    终止进程

    # kill -9 PID (PID 为查找到相应记录的第二个参数)
    kill -9 847

    意外情况1.

    nohup: ignoring input and appending output to ‘nohup.out’

    解决方案:

    #php server.php替换成你要执行的代码
    nohup php server.php  </dev/null &>/dev/null &

    相关文章

      网友评论

          本文标题:使程序在Linux下后台运行 (关掉终端继续让程序运行的方法)

          本文链接:https://www.haomeiwen.com/subject/hnpebxtx.html