Normally we log in a Linux machine using ssh. And when we logs out, those jobs started by the shell will get killed if they're not deamon or running at backend. [b]nohup[/b] is a useful tool to keep the job running at backend to prevent this "auto killed" behavior from happening.
Here's how to use it:
We'll see something printed out:
Meaning it's up. All the output info of [i]myjob[/i] will be kept in nohup.out of the current directory.
If we logout, [i]myjob[/i] will keep running at the backend.
To kill [i]myjob[/i], normally we use the command below to find out the pid, and use the [i]kill[/i] command to stop the process.
Here's how to use it:
# nohup myjob &
We'll see something printed out:
appending output to nohup.out
Meaning it's up. All the output info of [i]myjob[/i] will be kept in nohup.out of the current directory.
If we logout, [i]myjob[/i] will keep running at the backend.
To kill [i]myjob[/i], normally we use the command below to find out the pid, and use the [i]kill[/i] command to stop the process.
ps -A | grep myjob
本文介绍如何利用nohup命令使Linux中的任务在后台持续运行,即使用户登出也不受影响。通过nohup命令启动的任务会将输出重定向到nohup.out文件,并且可以通过ps和grep组合命令来查找并使用kill命令结束该任务。
691

被折叠的 条评论
为什么被折叠?



