如何将一个以 sudo 启动的正在运行的进程发送到后台?

Bar*_*rth 5 terminal sudo background-process

我刚刚安装了 SLC6(源自 RHEL6 的 SL6)。我可以通过在启动它的终端中按 Ctrl-Z 将正在运行的进程发送到后台。但是,当我用sudo启动命令时,我无法做到。它曾经在 SLC5 中无缝工作。

我可以做任何配置来允许这样做吗?

编辑这是我尝试运行的命令示例:

[user@pcald02 ~]$ sudo emacs
^Z^C
Run Code Online (Sandbox Code Playgroud)

Ctrl-Z 使符号 ^Z 出现,但没有其他任何反应。现在我意识到即使是 Ctrl-C 也是无效的。

没有 sudo :

[user@pcald02 ~]$ emacs
^Z
[1]+  Stopped                 emacs
[user@pcald02 ~]$ 
Run Code Online (Sandbox Code Playgroud)

slm*_*slm 5

如果我理解您的问题,以下内容在 CentOS 6.4 上对我来说效果很好,我希望它与 SLC6 非常相似:

初始命令
$ sudo sleep 300
^Z
[1]+  Stopped                 sudo sleep 300
Run Code Online (Sandbox Code Playgroud) 背景
$ bg
[1]+ sudo sleep 300 &

$ jobs
[1]+  Running                 sudo sleep 300 &

$ ps -eaf|grep sudo
root     25752 25669  0 09:53 pts/0    00:00:00 sudo sleep 300
sam      25755 25669  0 09:53 pts/0    00:00:00 grep sudo
Run Code Online (Sandbox Code Playgroud) 杀死作业 ( Ctrl+ C)
$ fg
sudo sleep 300
^C

$ ps -eaf|grep sudo
sam      25758 25669  0 09:53 pts/0    00:00:00 grep sudo
Run Code Online (Sandbox Code Playgroud) 操作系统信息
$ uname -a
Linux mungr 2.6.32-358.6.1.el6.x86_64 #1 SMP Tue Apr 23 19:29:00 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

$ cat /etc/redhat-release 
CentOS release 6.4 (Final)
Run Code Online (Sandbox Code Playgroud)


tri*_*eee 2

我猜这里真正的问题是您尝试运行的命令是 Emacs。以 root 身份运行 Emacs 绝不是一个好主意。Emacs 还会覆盖许多击键,因此C-z可能仅仅因为这个原因而无法工作。如果root已经登录,可能会在显示屏emacs上以图形方式启动。root等等等等.

查看使用sudo:Tramp 中的方法从 Emacs 中编辑文件sudo。例如,要编辑/etc/motd,请执行C-x C-f并将路径键入为/sudo:root@localhost:/etc/motd