nohup和&

nohup,不挂断地运行命令。

nohup运行由 Command参数和任何相关的 Arg参数指定的命令,忽略所有挂断(SIGHUP)信号;

用法: 

nohup COMMAND [ARG]...
or: nohup OPTION                         

 忽略所有挂断(SIGHUP)信号

--help 

--version 

If standard input is a terminal, redirect it from /dev/null.
If standard output is a terminal, append output to `nohup.out' if possible,
`$HOME/nohup.out' otherwise.
If standard error is a terminal, redirect it to standard output.
To save output to FILE, use `nohup COMMAND > FILE'.

 0 – stdin (standard input),1 – stdout (standard output),2 – stderr (standard error) ;

: 指在后台运行

nohup : 不挂断的运行,注意并没有后台运行的功能,,就是指,用nohup运行命令可以使命令永久的执行下去,和用户终端没有关系,例如我们断开SSH连接都不会影响他的运行,注意了nohup没有后台运行的意思;&才是后台运行

&是指在后台运行,但当用户推出(挂起)的时候,命令自动也跟着退出

那么,我们可以巧妙的吧他们结合起来用就是
nohup COMMAND &
这样就能使命令永久的在后台执行
 
 
 jobs 

LINUX任务(jobs)详解

在用管理员执行一个命令后,用Ctrl+Z把命令转移到了后台。导致无法退出root的。


输入命令:exit
终端显示:There are stopped jobs.

解决方法:
方法一、输入命令:jobs
终端显示:[1]+ Stopped vim /etc/network/interfaces > /home/leo/Desktop/ip.txt (wd: /)

KILL %1

方法二、输入命令:jobs -l
终端显示:[1]+ 4664 停止 vim /etc/network/interfaces > /home/leo/Desktop/ip.txt (wd: /)

看到4664,这个就是PID了

现在开始杀掉它:
输入命令:kill 4664
终端没有显示。ok。

再用jobs命令查看,确认已经杀掉了

Linux Jobs等前后台运行命令解

A,Shell支持作用控制,有以下命令: 
1. command& 让进程在后台运行 
2. jobs 查看后台运行的进程 
3. fg %n 让后台运行的进程n到前台来 
4. bg %n 让进程n到后台去;   
PS:"n"为jobs查看到的进程编号.

原文地址:https://www.cnblogs.com/zhco/p/11281682.html