Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 如何在shell中启动作业,即使启动该作业的shell终止,该作业仍将持续_Linux_Shell_Background Process - Fatal编程技术网

Linux 如何在shell中启动作业,即使启动该作业的shell终止,该作业仍将持续

Linux 如何在shell中启动作业,即使启动该作业的shell终止,该作业仍将持续,linux,shell,background-process,Linux,Shell,Background Process,如何在Linux shell中启动作业,以便即使启动它的shell终止,该作业仍将持续 更具体地说,我试图在一个进程上运行strace。如果我在一个终端上运行,它会运行得很好。但是,我想在一个远程shell中执行它,它将在所有命令执行完毕后立即停止“strace-ppid&”没有任何效果,因为当shell停止时,后台作业也会被终止 我该怎么做 nohup似乎是我要找的东西。但是,sshuser@remote_machine脚本名称似乎也没有任何效果。在脚本中,我有“nohup strace-p

如何在Linux shell中启动作业,以便即使启动它的shell终止,该作业仍将持续

更具体地说,我试图在一个进程上运行strace。如果我在一个终端上运行,它会运行得很好。但是,我想在一个远程shell中执行它,它将在所有命令执行完毕后立即停止<代码>“strace-ppid&”没有任何效果,因为当shell停止时,后台作业也会被终止

我该怎么做

nohup
似乎是我要找的东西。但是,
sshuser@remote_machine脚本名称
似乎也没有任何效果。在脚本中,我有“nohup strace-p pid”


非常感谢

Nohup
Screen
可用于运行命令,即使会话已断开或用户已注销。我两者都用,但“屏幕”更好

nohup ./<script_name> &
在任务窗口中执行命令,如果任务未完成,请使用

$ Ctrl+a+d
to save the task. It will show the following info:
[detached]
如果任务已完成,请使用“退出”退出屏幕:

    $ exit

[screen is terminating]
您可以使用
screen-ls
查找任何屏幕信息:

$ screen -ls
There is a screen on:
10000.task (Detached)
使用“screen-r”恢复任务:

$ screen -r 10000
你可以用“屏幕”! 用法:

您的任务将继续运行。如果您想返回,只需键入:

screen -r


除了其他答案之外,您可能还希望使用该命令(可能通过ssh
ssh
)进行远程访问,例如

  batch << ENDBATCH
    strace -p 1234 -o /tmp/trace.file
  ENDBATCH

batch nohup似乎是我要找的东西。但是宋承宪user@remote_machine似乎也没有任何效果。在脚本中我有“nohup strace-p pid”,你需要在nohup命令的末尾加上“&”,比如“nohup strace-p pid&”,它将把进程放在后台还有
disown
/script\u name&disown-h
试试nohup strace-p pid&
screen -r
screen -r -d (to detach old sessions)
  batch << ENDBATCH
    strace -p 1234 -o /tmp/trace.file
  ENDBATCH