另外的那个回答有点答非所问,nohup是通用,但ngrok不支持。我试过最简单的办法是:
1、安装screen命令:#yum install screen。Debian/Ubuntu用apt命令,我不太会。
2、#screen -S [name] 。name随便写,S大写。这里屏幕会清屏一下,不用管。
3、运行ngrok(#./ngrokd -***=*** sub***=80)这里忘了具体怎么打
4、日志刷出来之后,直接关掉ssh窗口就行,不要按ctrl+c,现在就是后台运行了。
5、想停掉ngrok,ssh上服务器,用#screen -r [name],就会回到ngrok窗口。[name]忘了的话,用#ps -ef能看到screen进程。
上面带#号就是要敲的命令。
一、在Linux中,如果要让进程在后台运行,一般情况下,我们在命令后面加上即可,实际上,这样是将命令放入到一个作业队列中了:
$ ./test.sh [1] 17208 $ jobs -l [1]+ 17208 Running ./test.sh
二、对于已经在前台执行的命令,也可以重新放到后台执行,首先按ctrl+z暂停已经运行的进程,然后使用bg命令将停止的作业放到后台运行:
$ ./test.sh [1]+ Stopped ./test.sh $ bg %1 [1]+ ./test.sh $ jobs -l [1]+ 22794 Running ./test.sh
三、但是如上方到后台执行的进程,其父进程还是当前终端shell的进程,而一旦父进程退出,则会发送hangup信号给所有子进程,子进程收到hangup以后也会退出。如果我们要在退出shell的时候继续运行进程,则需要使用nohup忽略hangup信号,或者setsid将将父进程设为init进程(进程号为1)
$ echo $$ 21734 $ nohup ./test.sh [1] 29016 $ ps -ef | grep test 515 29710 21734 0 11:47 pts/12 00:00:00 /bin/sh ./test.sh 515 29713 21734 0 11:47 pts/12 00:00:00 grep test
$ setsid ./test.sh [1] 409 $ ps -ef | grep test 515 410 1 0 11:49 ? 00:00:00 /bin/sh ./test.sh 515 413 21734 0 11:49 pts/12 00:00:00 grep test