- 浏览: 4733246 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
bzhao:
你也应该可以这样:(not tested)./rbtunnel ...
在Bash脚本中怎么关闭文件描述符? -
bzhao:
如果有A进程原代码情况下,通过如下调用,把他的子进程继承关闭则 ...
在Bash脚本中怎么关闭文件描述符? -
Master-Gao:
楼主咋没分析下源码呢?
我使用过的Linux命令之dirname - 截取给定路径的目录部分 -
jiedushi:
tail -F 就可以吧
Linux下实时跟踪log4j日志文件的bash脚本 - 增强了tail -f的功能 -
java_is_new:
新手学习了,就是不明白为一个网卡配多个ip有什么用
我使用过的Linux命令之ifconfig - 网络配置命令
我使用过的Linux命令之nohup - 执行其他命令,并且忽略SIGHUP信号
本文链接:http://codingstandards.iteye.com/blog/835536 (转载请注明出处)
用途说明
nohup命令可以用来执行其他命令,并且忽略SIGHUP信号(run a command immune to hangups, with output to a non-tty。Run COMMAND, ignoring hangup signals.)当一个虚拟终端的网络连接断开时,操作系统向正在运行的程序发送SIGHUP信号(HUP = HangUP、挂断),默认情况下这个信号将使程序退出。
nohup命令通常用来把一个程序在后台来运行(需要&来配合),另外一个命令setsid也可以做到,如果系统中安装了screen,可以用screen来管理那些需要长时间运行的任务。本文后面提供的相关资料很详细的说明了这些命令,你也可以参考本系列之《我使用过的Linux命令之screen - 虚拟终端屏幕管理器 》。
常用参数
常用格式如下:
nohup command [arg] ... &
运行命令command,忽略SIGHUP信号,后台执行。输出信息会保存到nohup.out文件中。`nohup' runs the given COMMAND with hangup signals ignored, so that the command can continue running in the background after you log out.
nohup COMMAND [ARG]...
以下内容来自 info nohup。
如果标准输入是终端,将被重定向为/dev/null。(If standard input is a terminal, it is redirected from `/dev/null' so that terminal sessions do not mistakenly consider the terminal to be used by the command. This is a GNU extension; programs intended to be portable to non-GNU hosts should use `nohup COMMAND [ARG]... </dev/null' instead.)
如果标准输出是终端,将被重定向到nohup.out,采用追加模式,如果这个文件不能写,就重定向到$HOME/nohup.out文件。(If standard output is a terminal, the command's standard output is appended to the file `nohup.out'; if that cannot be written to, it is appended to the file `$HOME/nohup.out'; and if that cannot be written to, the command is not run. Any `nohup.out' or `$HOME/nohup.out' file created by `nohup' is made readable and writable only to the user, regardless of the current umask settings.)
如果标准错误是终端,将被输出到标准输出同样的文件中。( If standard error is a terminal, it is redirected to the same file descriptor as the (possibly-redirected) standard output.)
nohup命令不会自动将命令后台运行,所以你必须自己在命令后面加上&,把命令变成后台执行。( `nohup' does not automatically put the command it runs in the background; you must do that explicitly, by ending the command line with an `&'. Also, `nohup' does not alter the niceness of COMMAND; use `nice' for that, e.g., `nohup nice COMMAND'.)
要注意的是,跟在nohup后面的命令不能是内建命令。(COMMAND must not be a special built-in utility (*note Special built-in utilities::).)
退出码:(Exit status: 126 if COMMAND is found but cannot be invoked,127 if `nohup' itself fails or if COMMAND cannot be found,the exit status of COMMAND otherwise)
使用示例
示例一 后台执行命令并跟踪输出
[root@new55 test3]# nohup spider & tail -f nohup.out
[1] 18162
UUUUUUU [http://news.sina.com.cn/w/2010-09-20/084518138839s.shtml]
UUUUUUU [http://news.sina.com.cn/w/2010-06-20/090817680377s.shtml]
UUUUUUU [http://news.sina.com.cn/w/2010-06-18/164717673976s.shtml]
UUUUUUU [http://news.sina.com.cn/w/2010-06-18/075520496242.shtml]
UUUUUUU [http://news.sina.com.cn/w/2010-06-18/031720494028.shtml]
UUUUUUU [http://news.sina.com.cn/w/2010-06-18/101720497276.shtml]
UUUUUUU [http://i1.sinaimg.cn/dy/2010/0624/S12709T1277336424126.jpg]
UUUUUUU [hthttp://blog.sina.com.cn/s/blog_4a3131f00100j4d9.html?tj=1]
url=[hthttp://blog.sina.com.cn/s/blog_4a3131f00100j4d9.html?tj=1] schema[hthttp]
spider: test8.cpp:1051: int extract_url(const std::string&, PageInfo&, UrlPosMap&): Assertion `false' failed.
nohup: appending output to “nohup.out”
load spider.xml ok
<spider>
<start>
<url>http://www.sina.com.cn/</url>
</start>
<accept>
<prefix>http://www.sina.com.cn/</prefix>
<prefix>http://news.sina.com.cn/</prefix>
</accept>
<ignore>
<type>IMG</type>
</ignore>
</spider>
start node found
url http://www.sina.com.cn/
accept node found
prefix http://www.sina.com.cn/
prefix http://news.sina.com.cn/
ignore node found
type IMG
问题思考
相关资料
【1】einit 用nohup命令让Linux下程序永远在后台执行
【2】IBM Linux 技巧:让进程在后台可靠运行的几种方法
【3】IBM 学习 Linux,101: 创建、监控和终止进程
【4】IBM linux 技巧:使用 screen 管理你的远程会话
发表评论
-
在Linux用tar归档压缩文件时忽略某些文件和目录
2013-02-01 10:19 16929在Linux下,常用tar对文 ... -
使用nmap扫描服务器端口的一次操作
2012-11-01 17:00 15077使用nmap扫描服务器端口的一次操作 本文来自:http ... -
我使用过的Linux命令之wget - ooo
2011-09-14 13:10 0我使用过的Linux命令之wg ... -
推荐一篇学习Vim使用的好文:酷壳 - 简明 Vim 练级攻略
2011-09-09 12:53 9087简明 Vim 练级攻略 http://coolshell.c ... -
推荐一篇学习Vim使用的好文:酷壳 - 简明 Vim 练级攻略
2011-09-09 12:49 1简明 Vim 练级攻略 http://coolshell.c ... -
我使用过的Linux命令之:(冒号) - 啥也不做(除了……)
2011-08-29 13:18 11990我使用过的Linux命令之: ... -
我使用过的Linux命令之date - 显示、修改系统日期时间
2011-08-25 09:21 41906我使用过的Linux命令之da ... -
我使用过的Linux命令之declare - 声明shell变量(不知道没关系、知道了就更好的内建命令)
2011-08-16 09:22 21746我使用过的Linux命令之declare - 声明shell变 ... -
我使用过的Linux命令之alias - 设置命令的别名,让 Linux 命令更简练
2011-08-11 09:31 28719我使用过的Linux命令之alias - 设置命令的别名,让 ... -
我使用过的Linux命令之ar - 创建静态库.a文件
2011-08-08 10:40 51818我使用过的Linux命令之ar - 创建静态库.a文件 本 ... -
我使用过的Linux命令之crontab - 设置例行任务(类似于Windows中的任务计划)
2011-08-04 22:26 9694我使用过的Linux命令之crontab - 设置例行任务(类 ... -
我使用过的Linux命令之chmod - 改变文件/目录的访问权限
2011-08-03 21:33 10644我使用过的Linux命令之chmod - 改变文件/目录的访问 ... -
我使用过的Linux命令之export - 设置或显示环境变量
2011-08-02 19:55 25373我使用过的Linux命令之export - 设置或显示环境变量 ... -
我使用过的Linux命令之wc - 统计文件行数、单词数或字节数
2011-07-26 10:50 28934我使用过的Linux命令之wc - 统计文件行数、单词数或字节 ... -
我使用过的Linux命令之groupdel - 删除群组
2011-07-22 22:13 9622我使用过的Linux命令之gr ... -
我使用过的Linux命令之ifconfig - 网络配置命令
2011-07-21 20:43 60382我使用过的Linux命令之ifconfig - 网络配置命令 ... -
我使用过的Linux命令之ll - 列出文件/目录的详细信息
2011-07-20 21:22 7112我使用过的Linux命令之ll ... -
我使用过的Linux命令之mkdir - 创建目录
2011-07-20 20:58 13608我使用过的Linux命令之mkdir - 创建目录 本文链 ... -
我使用过的Linux命令之perror - 解释错误代码
2011-07-18 20:29 24974我使用过的Linux命令之perror - 解释错误代码 ... -
我使用过的Linux命令之ping - 测试与目标主机的连通性
2011-07-16 10:46 26268我使用过的Linux命令之ping - 测试与目标主机的连通性 ...
相关推荐
Python – paramiko 模块远程执行ssh 命令 nohup 不生效的问题解决 1、使用 paramiko 模块ssh 登陆到 linux 执行nohup命令不生效 # 执行命令 def command(ssh_config, cmd, result_print=None, nohup=False): ssh ...
linux下nohup日志输出过大问题的解决方法
主要涉及Linux下对nohup的日志按照每天定时拆分生成新的日志并清空nohup原来的日志
linux nohup 命令详解 自己留用
主要介绍了详解linux下nohup日志输出过大问题解决方案,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
描述:nohup 命令运行由 Command 参数和任何相关的 Arg 参数指定的命令,忽略所有挂断(SIGHUP)信号。在注销后使用 nohup 命令运行后台中的程序。要运行后台中的 nohup 命令,添加 & ( 表示”and”的符号)到命令...
一般运行linux上的程序都是执行 .sh 文件(./sh文件),那如果不影响当前CMD窗口的操作,需要后台运行怎么办呢? 这时就需要借助 nohup 和 & 命令来实现。 nohup java -server -Xms128M -Xmx512M -XX:MetaspaceSize...
Unix中 nohup 命令功能就是不挂断地运行命令,同时 nohup 把程序的所有输出到放到当前目录 nohup.out 文件中,如果文件不可写,则放到 <用户主目录>/nohup.out 文件中。那么有了这个命令以后我们php就写成shell ...
当我们在终端或控制台工作时,可能不希望由于运行一个作业而占住了屏幕,因为可能还有...在后台运行作业时要当心:需要用户交互的命令不要放在后台执行,因为这样你的机器就会在那里傻等。不过,作业在后台运行一样会将
当单纯的nohup命令不能起到在当前窗口关闭后仍可以执行某个操作或展示时,试试这个脚本吧,绝对可用。下载下来把里面的文件名称改一下,搜索的线程名字改一下,保存后用nohup执行,窗口关闭后也能保证程序不挂掉,好...
nohup命令可以将程序以忽略挂起信号的方式运行起来,被运行的程序的输出信息将不会显示到终端。 无论是否将 nohup 命令的输出重定向到终端,输出都将附加到当前目录的 nohup.out 文件中。如果当前目录的 nohup.out ...
使用nohup将训练程序后台不间断运行+随时查看训练情况输出与可视化使用服务器进行远程训练nohup指令和查看输出缺省输出文件的写法指定输出文件的写法和CUDA一起用实时查看out配合visdom使用 使用服务器进行远程训练 ...
nohup命令的全称为“no hang up”,该命令可以将程序以忽略挂起信号的方式运行起来,被运行的程序的输出信息将不会显示到终端。 无论是否将 nohup 命令的输出重定向到终端,输出都将附加到当前目录的 nohup.out 文件...
我自己总结的linux常用命令,来源于日常积累的各种网页博客。因为不耐烦反复的查,索性自己总结了一个pdf,里面包括常用的linux命令,包括gcc,grep,tar,sed,find,screen,nohup,scp等,另外还有一些常用的文本处理...
使用方法,解压到本地目录,配置path,即可在dos下使用linux命令。 windows下能直接执行的linux命令,基本包括日常所有,如:[.exe grolbp.exe regtool.exe a2p.exe grolj4.exe rm.exe a2p5.10.0.exe grops.exe ...
入门
nohup.out