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 ~]#	 

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

  1. First off I would like to say great blog! I had a quick question which I’d like to ask if you do not
    mind. I was curious to find out how you center yourself and clear
    your thoughts before writing. I’ve had a hard time clearing my thoughts in getting my thoughts out.

    I do take pleasure in writing but it just seems like the first 10 to 15 minutes are generally
    wasted just trying to figure out how to begin. Any ideas or tips?
    Kudos!

    回复
  2. hello!,I like your writing so a lot! share we communicate extra about your post on AOL?
    I need an expert on this house to unravel my problem.
    Maybe that’s you! Looking ahead to see you.

    回复
  3. Heya! I just wanted to ask if you ever have
    any problems with hackers? My last blog (wordpress) was hacked and
    I ended up losing several weeks of hard work due to no data backup.
    Do you have any methods to protect against hackers?

    回复
  4. First of all I want to say excellent blog! I had a quick question in which I’d like to
    ask if you do not mind. I was interested to know how you center yourself and clear your thoughts before writing.
    I’ve had trouble clearing my mind in getting my thoughts out there.
    I do enjoy writing however it just seems like the first 10 to
    15 minutes are generally wasted simply just trying to figure
    out how to begin. Any ideas or hints? Many thanks!

    回复
  5. Hi there everybody, here every person is sharing these familiarity,
    therefore it’s pleasant to read this website, and I used
    to pay a visit this webpage everyday.

    回复
  6. These are genuinely wonderful ideas in on the topic of blogging.
    You have touched some fastidious things here.
    Any way keep up wrinting.

    回复
  7. This is very interesting, You are a very skilled blogger.

    I’ve joined your feed and look forward to seeking more of your
    magnificent post. Also, I have shared your website in my social networks!

    回复
  8. Appreciate this post. Let me try it out.

    回复
  9. tarif is tarifs is

    回复
  10. viagra sildenafil tabs

    回复
  11. generic viagra on a plane

    回复
  12. try it viagra price online

    回复
  13. i recommend viagra from canada

    回复
  14. in tijuana is at be

    回复
  15. cipla viagra stores

    回复
  16. pfizer workshops viagra

    回复
  17. viagra brand uk

    回复

发表评论

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