LSX-blog

Feed Rss

【收录】让进程在后台可靠运行

04.28.2012, Linux, by .

我们经常会碰到这样的问题,用 telnet/ssh 登录了远程的 Linux 服务器,运行了一些耗时较长的任务, 结果却由于网络的不稳定导致任务中途失败。如何让命令提交后不受本地关闭终端窗口/网络断开连接的干扰呢?下面举了一些例子, 您可以针对不同的场景选择不同的方式来处理这个问题。

1. nohup

nohup 无疑是我们首先想到的办法。顾名思义,nohup 的用途就是让提交的命令忽略 hangup 信号。让我们先来看一下 nohup 的帮助信息:

NOHUP(1)                        User Commands                        NOHUP(1)

NAME
       nohup - run a command immune to hangups, with output to a non-tty

SYNOPSIS
       nohup COMMAND [ARG]...
       nohup OPTION

DESCRIPTION
       Run COMMAND, ignoring hangup signals.

       --help display this help and exit

       --version
              output version information and exit 

可见,nohup 的使用是十分方便的,只需在要处理的命令前加上 nohup 即可,标准输出和标准错误缺省会被重定向到 nohup.out 文件中。一般我们可在结尾加上"&"来将命令同时放入后台运行,也可用">filename 2>&1"来更改缺省的重定向文件名。

nohup 示例

                
[root@pvcent107 ~]# nohup ping www.lishixin.net &
[1] 3059
nohup: appending output to `nohup.out'
[root@localhost ~]# ps -ef |grep 3059
root      3059   984  0 21:06 pts/3    00:00:00 ping www.lishixin.net
root      3067   984  0 21:06 pts/3    00:00:00 grep 3059
[root@localhost ~]#	 

【收录】让进程在后台可靠运行 有 83 条回应

  1. Great article. I am going through some of these issues as well..

    回复
  2. I’m amazed, I must say. Rarely do I encounter a blog that’s both equally educative and interesting, and without a doubt, you’ve hit the nail on the head. The issue is something which not enough folks are speaking intelligently about. I’m very happy that I stumbled across this in my hunt for something relating to this.

    回复
  3. Aw, this was a really good post. Finding the
    time and actual effort to create a great article… but what can I
    say… I put things off a whole lot and don’t seem to get anything
    done.

    回复
  4. Wonderful work! That is the kind of information that are supposed to be shared around the net.
    Disgrace on the seek engines for not positioning this submit higher!
    Come on over and talk over with my site . Thanks =)

    回复
  5. Good web site you have got here.. It’s difficult to find quality writing
    like yours nowadays. I truly appreciate individuals like
    you! Take care!!

    回复
  6. Everyone loves what you guys tend to be up too. This sort of clever work and coverage!
    Keep up the good works guys I’ve included you guys to our blogroll.

    回复
  7. What’s up, just wanted to say, I enjoyed this blog post. It was practical.
    Keep on posting!

    回复
  8. Now I am going to do my breakfast, when having my breakfast coming
    again to read additional news.

    回复
  9. Hello, I enjoy reading through your article. I wanted to write a little
    comment to support you.

    回复
  10. Excellent post! We will be linking to this great post on our website.
    Keep up the good writing.

    回复
  11. Hey there! Do you know if they make any plugins to safeguard against hackers?
    I’m kinda paranoid about losing everything I’ve worked hard on.
    Any tips?

    回复
  12. Hello there! This is kind of off topic but I need some advice from an established blog.
    Is it hard to set up your own blog? I’m not very techincal but I can figure things out pretty quick.
    I’m thinking about creating my own but I’m not sure
    where to start. Do you have any ideas or suggestions?
    Cheers

    回复
  13. I just like the valuable info you provide on your articles.
    I’ll bookmark your weblog and check once more right here frequently.

    I am somewhat certain I will be told many new stuff proper here!
    Best of luck for the next!

    回复
  14. Everything is very open with a really clear explanation of the issues.
    It was really informative. Your site is extremely helpful.
    Thanks for sharing!

    回复
  15. It’s the best time to make some plans for the long
    run and it is time to be happy. I have read
    this publish and if I could I wish to counsel you few attention-grabbing things or tips.
    Maybe you could write subsequent articles referring to this
    article. I desire to read even more issues about it!

    回复
  16. Wow, superb weblog format! How lengthy have you
    been blogging for? you make blogging look easy. The entire glance of
    your web site is wonderful, as neatly as the content!

    回复
  17. I think that is one of the so much vital information for me.

    And i’m happy studying your article. But should observation on some normal
    things, The website taste is ideal, the articles
    is really nice : D. Excellent task, cheers

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

    回复
  19. It’s very simple to find out any matter on net as
    compared to textbooks, as I found this paragraph at this site.

    回复
  20. Sweet blog! I found it while browsing on Yahoo News. Do you have
    any tips on how to get listed in Yahoo News? I’ve
    been trying for a while but I never seem to get there!

    Cheers

    回复
  21. Pretty nice post. I just stumbled upon your
    weblog and wished to say that I have really enjoyed browsing your blog posts.

    In any case I will be subscribing to your feed and
    I hope you write again soon!

    回复
  22. Hello to every one, it’s genuinely a pleasant for me to visit
    this web page, it includes useful Information.

    回复
  23. I have been exploring for a bit for any high-quality articles or blog posts in this kind of house .

    Exploring in Yahoo I eventually stumbled upon this
    web site. Studying this information So i am satisfied to convey that I have a very excellent uncanny feeling I discovered just what I needed.
    I so much certainly will make certain to don?t
    fail to remember this site and give it a glance regularly.

    回复
  24. Awesome! Its truly awesome post, I have got much clear idea on the topic of from this paragraph.

    回复
  25. You could definitely see your enthusiasm in the work
    you write. The sector hopes for even more passionate writers such as
    you who aren’t afraid to say how they believe.
    Always follow your heart.

    回复
  26. It’s remarkable designed for me to have a web page,
    which is beneficial in favor of my experience. thanks admin

    回复
  27. I think the admin of this web site is genuinely working hard in favor of his site, because here every data is quality based stuff.

    回复
  28. Spot on with this write-up, I really feel this amazing
    site needs much more attention. I’ll probably be returning to read through more, thanks for the
    info!

    回复
  29. Excellent, what a weblog it is! This blog provides helpful
    data to us, keep it up.

    回复
  30. Have you ever considered creating an ebook or guest authoring
    on other blogs? I have a blog centered on the same topics you discuss and would
    love to have you share some stories/information. I know my audience would appreciate your work.
    If you are even remotely interested, feel free to send me an e-mail.

    回复
  31. Howdy! Someone in my Myspace group shared this website with us
    so I came to give it a look. I’m definitely enjoying the information. I’m bookmarking and will be tweeting this to my followers!
    Great blog and excellent design and style.

    回复
  32. Painter And Decorator Gloucester
    38 Bruton Way
    Gloucester GL1 1DA, United Kingdom
    01452 223268

    回复
  33. viagra dosage side effects tag search [url=http://viagrawinner.com/#]sildenafil 20 mg tablet vs viagra[/url] buy viagra
    online without prescription viagra generic release date – cheapest genuine viagra viagra online buy generic viagra online

    回复

发表评论

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