即使在启动它的外壳终止的情况下,如何在仍将存在的外壳中启动作业 [英] How to launch a job in a shell which will persist even if the shell which launches it terminates

查看:61
本文介绍了即使在启动它的外壳终止的情况下,如何在仍将存在的外壳中启动作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何在Linux shell中执行一项工作,以便即使启动它的shell终止,该工作仍将继续存在?

How do I lauch a job in a Linux shell, so that even if the shell which launches it terminates, this job will still persist?

更具体地说,我正在尝试在进程上运行strace.如果我在终端机上运行,​​它将运行完美.但是,我想在一个远程外壳程序中执行此操作,该外壳程序将在所有命令执行完毕后立即停止. "strace -p pid &"没有任何作用,因为当shell停止时,后台作业也会被杀死.

More specifically, I am trying to run strace on a process. It runs perfectly if I do it in a terminal. However, I want to do it in a remote shell which will stop as soon as all the commands have been executed. "strace -p pid &" doesn't have any effect because when the shell stops, the background job also gets killed.

我应该怎么做?

nohup似乎是我要寻找的东西.但是,ssh user@remote_machine script_name似乎也没有任何作用.在脚本中,我有"nohup strace -p pid"

nohup seems to be thing I am looking for. However, ssh user@remote_machine script_name doesn't seem to have any effect neither. In the script I have "nohup strace -p pid"

非常感谢!

推荐答案

NohupScreen可以用于运行命令,即使会话断开连接或用户注销也是如此.我都使用它们,但是屏幕"更好.

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> &

如何使用屏幕?

创建任务

$ 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]

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

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

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

使用"screen -r"恢复任务:

Use "screen -r" to recover the task:

$ screen -r 10000

这篇关于即使在启动它的外壳终止的情况下,如何在仍将存在的外壳中启动作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆