两者都不符合我的流程。Out & or myprocess。出&设置我的进程。在后台运行。关闭终端后,进程仍在运行。 它们之间有什么区别?
当前回答
使用&号(&)将在子进程(当前bash会话的子进程)中运行该命令。但是,当您退出会话时,所有子进程将被杀死。
使用nohup + &(&)将完成同样的事情,除了会话结束时,子进程的父进程将被更改为“1”,即“init”进程,从而保护子进程不被杀死。
其他回答
The nohup command is a signal masking utility and catches the hangup signal. Where as ampersand doesn’t catch the hang up signals. The shell will terminate the sub command with the hang up signal when running a command using & and exiting the shell. This can be prevented by using nohup, as it catches the signal. Nohup command accept hang up signal which can be sent to a process by the kernel and block them. Nohup command is helpful in when a user wants to start long running application log out or close the window in which the process was initiated. Either of these actions normally prompts the kernel to hang up on the application, but a nohup wrapper will allow the process to continue. Using the ampersand will run the command in a child process and this child of the current bash session. When you exit the session, all of the child processes of that process will be killed. The ampersand relates to job control for the active shell. This is useful for running a process in a session in the background.
如果我说错了,请指正
nohup myprocess.out &
Nohup捕获挂起信号,这意味着当终端关闭时它将发送一个进程。
myprocess.out &
进程可以运行,但是一旦终端关闭,进程就会停止。
nohup myprocess.out
即使终端关闭,进程也能运行,但你可以在终端中按ctrl + z来停止进程。如果&存在,Crt +z不工作。
大多数情况下,我们使用ssh登录远程服务器。如果你启动一个shell脚本,然后注销,那么这个进程就会被杀死。 Nohup帮助在退出shell后继续在后台运行脚本。
Nohup command name &
eg: nohup sh script.sh &
Nohup接收HUP信号。 Nohup不会自动把工作放在后台。我们需要使用&显式地告诉它
使用&号(&)将在子进程(当前bash会话的子进程)中运行该命令。但是,当您退出会话时,所有子进程将被杀死。
使用nohup + &(&)将完成同样的事情,除了会话结束时,子进程的父进程将被更改为“1”,即“init”进程,从而保护子进程不被杀死。
myprocess.out & would run the process in background using a subshell. If the current shell is terminated (say by logout), all subshells are also terminated so the background process would also be terminated. The nohup command ignores the HUP signal and thus even if the current shell is terminated, the subshell and myprocess.out would continue to run in the background. Another difference is that & alone doesn't redirect the stdout/stderr so if there are any output or error, those are displayed on the terminal. nohup on the other hand redirect the stdout/stderr to nohup.out or $HOME/nohup.out.
推荐文章
- 检查bash变量是否等于0
- 在tmux中保持窗口名称固定
- 只使用md5sum获取哈希值(没有文件名)
- 如何生成一个核心转储在Linux上的分段错误?
- 在Python中如何在Linux和Windows中使用“/”(目录分隔符)?
- 在Bash中测试非零长度字符串:[-n "$var"]或["$var"]
- 如何删除超过X小时的文件
- 如何创建Bash别名?
- 将所有变量从一个shell脚本传递到另一个?
- 如何在Apache服务器上自动将HTTP重定向到HTTPS ?
- 如何删除shell脚本中文件名的扩展名?
- 使用xargs调用shell函数
- 如何限制从grep返回的结果的数量?
- 'find -exec'是Linux中的shell函数
- 将值从管道读入shell变量