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

2017-11-28  本文已影响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 &

上一篇下一篇

猜你喜欢

热点阅读