How to launch a job in a shell which will persist even if the shell which launches it terminates

走远了吗. 提交于 2019-12-04 15:27:25

Nohup and Screen can be used to run a command even if the session is disconnected or the user logs out. I use them both, but “Screen” is better.

nohup ./<script_name> &

How to use screen?

creat a task:

$ screen -S task

Execute a command in the task window,if your task not finished, use

$ Ctrl+a+d
to save the task. It will show the following info:
[detached]

if your task has been finished, use “exit” to exit screen:

    $ exit

[screen is terminating]

You can use screen -ls to find any screen info:

$ screen -ls
There is a screen on:
10000.task (Detached)

Use “screen -r” to recover the task:

$ screen -r 10000

you could use "screen"! Usage:

screen [Enter]
enter your command
[Ctrl] + [A] + [D(Detach)]

Your task continues running. If you want to go back to it just type in:

screen -r

or

screen -r -d (to detach old sessions)

In addition of other answers, you may want to use the batch(1) command (perhaps remotely thru ssh), like e.g.

  batch << ENDBATCH
    strace -p 1234 -o /tmp/trace.file
  ENDBATCH
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!