Linux 关掉shell依然保留进程方法

遇到一个棘手的需求,需要在后端跑到爬虫进程

刚开始是这样的,在后面加 &

$ ./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


146 thoughts on “Linux 关掉shell依然保留进程方法”

  • hey there and thank you for your info ? I?ve certainly picked up something new from right here. I did however expertise a few technical issues using this website, since I experienced to reload the site a lot of times previous to I could get it to load properly. I had been wondering if your web hosting is OK? Not that I’m complaining, but sluggish loading instances times will sometimes affect your placement in google and could damage your high quality score if advertising and marketing with Adwords. Anyway I?m adding this RSS to my email and can look out for a lot more of your respective fascinating content. Ensure that you update this again very soon..

  • Its like you read my mind! You seem to know a lot about this, like you wrote the book in it or something. I think that you can do with a few pics to drive the message home a bit, but other than that, this is excellent blog. A great read. I will definitely be back.

  • Thanks for the a new challenge you have disclosed in your text. One thing I would like to reply to is that FSBO relationships are built as time passes. By launching yourself to the owners the first end of the week their FSBO is actually announced, prior to the masses begin calling on Mon, you build a good interconnection. By giving them instruments, educational materials, free records, and forms, you become a strong ally. By using a personal affinity for them as well as their problem, you create a solid network that, on most occasions, pays off once the owners opt with an agent they know and trust — preferably you.

  • Thanks for your post. One other thing is that individual states have their very own laws that will affect householders, which makes it quite difficult for the our lawmakers to come up with the latest set of guidelines concerning property foreclosures on house owners. The problem is that each state has got own legislation which may interact in a negative manner in regards to foreclosure insurance plans.

  • You really make it seem so easy with your presentation but I find this matter to be really something which I think I would never understand. It seems too complicated and very broad for me. I’m looking forward for your next post, I?ll try to get the hang of it!

  • Very great post. I simply stumbled upon your blog and wanted to mention that I’ve truly enjoyed browsing your weblog posts. In any case I?ll be subscribing in your rss feed and I’m hoping you write again very soon!

  • I would like to thank you for the efforts you have put in penning this website. I am hoping to view the same high-grade content by you in the future as well. In fact, your creative writing abilities has inspired me to get my very own site now 😉

  • I just like the valuable info you provide in your articles. I will bookmark your weblog and take a look at once more right here frequently. I’m somewhat certain I?ll be informed plenty of new stuff proper right here! Best of luck for the following!

  • I have been browsing online greater than 3 hours nowadays, but I by no means discovered any attention-grabbing article like yours. It?s beautiful price enough for me. In my opinion, if all web owners and bloggers made just right content as you did, the internet will probably be much more useful than ever before.

  • Thanks for the ideas you have contributed here. Also, I believe there are numerous factors that keep your motor insurance premium lower. One is, to take into consideration buying motors that are inside the good set of car insurance providers. Cars that happen to be expensive tend to be more at risk of being lost. Aside from that insurance policies are also good value of your car or truck, so the more pricey it is, then the higher a premium you make payment for.

  • I do agree with all of the ideas you have presented in your post. They are really convincing and will certainly work. Still, the posts are too short for starters. Could you please extend them a bit from next time? Thanks for the post.

  • I have really learned some new things from your blog post. One other thing to I have noticed is that in many instances, FSBO sellers will probably reject anyone. Remember, they might prefer to not ever use your providers. But if anyone maintain a reliable, professional partnership, offering aid and remaining in contact for around four to five weeks, you will usually be capable to win a conversation. From there, a listing follows. Many thanks

  • I loved as much as you will receive carried out right here. The sketch is attractive, your authored subject matter stylish. nonetheless, you command get got an edginess over that you wish be delivering the following. unwell unquestionably come more formerly again since exactly the same nearly a lot often inside case you shield this hike.

  • Thanks for your post. I want to say that the tariff of car insurance will vary from one scheme to another, due to the fact there are so many different issues which contribute to the overall cost. One example is, the make and model of the motor vehicle will have a tremendous bearing on the cost. A reliable old family motor vehicle will have a less expensive premium than just a flashy sports car.

  • I have learned some significant things through your site post. One other subject I would like to say is that there are plenty of games that you can buy which are designed specially for preschool age kids. They include pattern recognition, colors, animals, and shapes. These normally focus on familiarization rather than memorization. This will keep children occupied without having the experience like they are learning. Thanks

  • One thing I have actually noticed is the fact there are plenty of common myths regarding the financial institutions intentions when talking about home foreclosure. One myth in particular is the bank desires your house. The lender wants your cash, not your own home. They want the amount of money they gave you with interest. Steering clear of the bank will draw the foreclosed summary. Thanks for your posting.

  • I have been exploring for a little bit for any high-quality articles or blog posts on this kind of area . Exploring in Yahoo I at last stumbled upon this site. Reading this information So i am happy to convey that I have a very good uncanny feeling I discovered just what I needed. I most certainly will make certain to do not forget this site and give it a glance regularly.

  • I have realized that car insurance businesses know the motors which are susceptible to accidents as well as other risks. They also know what types of cars are susceptible to higher risk and the higher risk they’ve the higher the particular premium price. Understanding the uncomplicated basics with car insurance will help you choose the right kind of insurance policy that can take care of the needs you have in case you become involved in an accident. Many thanks for sharing the ideas with your blog.

  • I have to thank you for the efforts you’ve put in writing this blog. I’m hoping to see the same high-grade blog posts from you later on as well. In truth, your creative writing abilities has encouraged me to get my very own blog now 😉

  • I have realized that of all types of insurance, health insurance is the most marked by controversy because of the discord between the insurance coverage company’s need to remain afloat and the client’s need to have insurance policy. Insurance companies’ revenue on overall health plans are certainly low, thus some providers struggle to generate income. Thanks for the ideas you share through this blog.

  • Hey very nice web site!! Man .. Excellent .. Amazing .. I will bookmark your site and take the feeds also?I am happy to find so many useful information here in the post, we need work out more strategies in this regard, thanks for sharing. . . . . .

  • Excellent site you have got here.. It’s difficult to find high-quality writing like yours nowadays. I seriously appreciate people like you! Take care!!

  • May I just say what a relief to find a person that genuinely knows what they’re talking about online. You definitely realize how to bring an issue to light and make it important. More people must read this and understand this side of your story. I was surprised you’re not more popular because you definitely possess the gift.

  • A fascinating discussion is worth comment. I think that you ought to publish more on this subject matter, it might not be a taboo matter but typically folks don’t discuss these subjects. To the next! Kind regards!

  • Hello, i think that i noticed you visited my web site thus i got here to ?go back the prefer?.I am trying to find things to enhance my web site!I assume its good enough to make use of a few of your ideas!!

发表评论

邮箱地址不会被公开。 必填项已用*标注

÷ 5 = 2