遇到一个棘手的需求,需要在后端跑到爬虫进程
刚开始是这样的,在后面加 &
$ ./test.sh &
关掉shell依然后kill掉进程,后来发现其父进程还是当前终端shell的进程,而一旦父进程退出,则会发送hangup信号给所有子进程,子进程收到hangup以后也会退出。如果要在退出shell的时候继续运行进程,则需要使用nohup忽略hangup信号,或者setsid将将父进程设为init进程(进程号为1)
详细代码是这样的:
$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
yum install -y screen
输入screen,然后输入你要运行的命令
ctrl+A 然后按D,screen会关闭
查看正在运行的程序
screen -ls
thanks a lot for this amazing blog
thanks for this blog
I am really inspired along with your writing skills as well as with the format for your blog. Is this a paid subject matter or did you modify it yourself? Either way keep up the excellent high quality writing, it’s uncommon to look a nice blog like this one today..|
I was curious if you ever thought of changing the layout of your website? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot of text for only having one or two images. Maybe you could space it out better?|
Oh my goodness! Amazing article dude! Thanks, However I am encountering problems with your RSS. I don’t know the reason why I am unable to subscribe to it. Is there anybody else getting similar RSS issues? Anyone that knows the answer will you kindly respond? Thanx!!|
It is perfect time to make some plans for the future and it’s time to be happy. I’ve read this post and if I could I desire to suggest you few interesting things or advice. Perhaps you can write next articles referring to this article. I wish to read more things about it!|
Really no matter if someone doesn’t understand after that its up to other viewers that they will help, so here it takes place.|