nohup和&后台运行,进程查看及终止 Linux教程


1.nohup

用途:不挂断地运行命令。


2.&

用途:在后台运行

一般两个一起用

nohup command &

eg: nohup /usr/local/node/bin/node /www/im/chat.js >> /usr/local/node/output.log 2>&1 &

进程号7585


3.查看运行的后台进程

(1)jobs -l

(2)ps -ef

ps -aux|grep chat.js

  用ps -def | grep查找进程很方便,最后一行总是会grep自己

  用grep -v参数可以将grep命令排除掉: ps -aux|grep chat.js| grep -v grep

  再用awk提取一下进程ID:ps -aux|grep chat.js| grep -v grep | awk '{print $2}'


4.如果某个进程起不来,可能是某个端口被占用

查看使用某端口的进程:lsof -i:8090    netstat -ap|grep 8090    

查看到进程id之后,使用netstat命令查看其占用的端口: netstat -nap|grep 7779   

终止后台运行的进程:kill -9  进程号


签名:这个人很懒,什么也没有留下!
最新回复 (0)
返回