原文:javascript
https://www.cnblogs.com/baby123/p/6477429.htmlhtml
1.nohupjava
用途:不挂断地运行命令。node
语法:nohup Command [ Arg … ] [ & ]spa
不管是否将 nohup 命令的输出重定向到终端,输出都将附加到当前目录的 nohup.out 文件中。code
若是当前目录的 nohup.out 文件不可写,输出重定向到 $HOME/nohup.out 文件中。htm
若是没有文件能建立或打开以用于追加,那么 Command 参数指定的命令不可调用。blog
2.&进程
用途:在后台运行ip
通常两个一块儿用
nohup command &
eg:
1
|
nohup /usr/local/node/bin/node /www/im/chat.js >> /usr/local/node/output.log 2>&1 &
|
进程号7585
查看运行的后台进程
(1)jobs -l
jobs命令只看当前终端生效的,关闭终端后,在另外一个终端jobs已经没法看到后台跑得程序了,此时利用ps(进程查看命令)
(2)ps -ef
1
|
ps -aux|grep chat.js
|
a:显示全部程序
u:以用户为主的格式来显示
x:显示全部程序,不以终端机来区分
注:
用ps -def | grep查找进程很方便,最后一行老是会grep本身
用grep -v参数能够将grep命令排除掉
1
|
ps -aux|grep chat.js| grep -v grep
|
再用awk提取一下进程ID
1
|
ps -aux|grep chat.js| grep -v grep | awk
'{print $2}'
|
3.若是某个进程起不来,多是某个端口被占用
查看使用某端口的进程
1
|
lsof -i:8090
|
1
|
netstat -ap|grep 8090
|
查看到进程id以后,使用netstat命令查看其占用的端口
1
|
netstat -nap|grep 7779
|
使用kill杀掉进城后再启动
4.终止后台运行的进程
1
|
kill -9 进程号
|