遇到一个棘手的需求,需要在后端跑到爬虫进程
刚开始是这样的,在后面加 &
1 |
$ ./test.sh & |
关掉shell依然后kill掉进程,后来发现其父进程还是当前终端shell的进程,而一旦父进程退出,则会发送hangup信号给所有子进程,子进程收到hangup以后也会退出。如果要在退出shell的时候继续运行进程,则需要使用nohup忽略hangup信号,或者setsid将将父进程设为init进程(进程号为1)
详细代码是这样的:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
$nohup ./test.sh & $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 |
安装screen
1 |
yum install -y screen |
输入screen,然后输入你要运行的命令
ctrl+A 然后按D,screen会关闭
查看正在运行的程序
1 |
screen -ls |
lipitor generic
http://www.pandoraonline-shop.de/ Pandora
http://www.yeezy-shoe.us.com/ Yeezy Shoes
http://www.uggs-officialsite.org/ Uggs Official Site
Many thanks. I like it. top rated online canadian pharmacies
Incredible quite a lot of useful facts. viagra for sale uk
Very good material. Regards. canada pharmaceutical online ordering
You actually suggested that really well. northwest pharmacy
You suggested that exceptionally well. hemp oil vs cbd oil
Perfectly spoken indeed. ! Cialis 20 Mg Receta
Awesome advice. Cheers. viagra
You actually suggested this superbly! online pharmacies of canada
Cheers. A lot of data!
cbd oil dosage