关闭终端后如何保持应用程序运行?

odb*_*ele 22 command-line

我是 Ubuntu 的新手。我用过 Sublime Text。我意识到在我从终端打开 Sublime Text 后,如果我关闭终端,应用程序会继续运行。对于其他应用程序(如geany.

从终端打开应用程序后,当我关闭终端时,应用程序也会关闭。我试过&exitgeany &exit. 但这不是我要找的。

geany关闭后如何继续运行?

Ter*_*nce 31

编辑:这可能仅适用于某些类型的终端。最好disown在启动如下命令后再运行一个命令,以便应用程序与终端窗口解除关联。


在终端窗口中,输入

nohup geany > /dev/null
disown
Run Code Online (Sandbox Code Playgroud)

或者

nohup geany >/dev/null &
disown
Run Code Online (Sandbox Code Playgroud)

nohup允许应用程序运行并且不受挂起影响,因此关闭终端窗口不会影响正在运行的应用程序。向>/dev/null命令添加可防止在nohup.out运行应用程序的每个目录中创建。

从手册页:

NAME
       nohup - run a command immune to hangups, with output to a non-tty

SYNOPSIS
       nohup COMMAND [ARG]...
       nohup OPTION
Run Code Online (Sandbox Code Playgroud)

$ disown --help
disown: disown [-h] [-ar] [jobspec ... | pid ...]
    Remove jobs from current shell.
    
    Removes each JOBSPEC argument from the table of active jobs.  Without
    any JOBSPECs, the shell uses its notion of the current job.
    
    Options:
      -a    remove all jobs if JOBSPEC is not supplied
      -h    mark each JOBSPEC so that SIGHUP is not sent to the job if the
            shell receives a SIGHUP
      -r    remove only running jobs
    
    Exit Status:
    Returns success unless an invalid option or JOBSPEC is given.
Run Code Online (Sandbox Code Playgroud)

  • 可能是 `nohup geany > /dev/null` 或 `nohup geany > /dev/null &`,以防止每次运行命令时在当前工作目录中创建一个 `nohup.out` 文件 (2认同)

mni*_*iip 13

作为替代方案,nohup您可以使用 shell builtin disowndisown从作业列表中删除作业,并且当 shell 存在时,SIGHUP不会发送到该进程。

geany &
disown
exit
Run Code Online (Sandbox Code Playgroud)