以 sudo 在后台运行程序

问题描述 投票:0回答:4

我在 Linux 虚拟机上,我正在尝试运行命令

sudo synaptic &
,该命令应该在后台启动 synaptic。但是,它不要求输入密码,并且程序似乎无法启动。我之前没有输入密码,因为运行任何其他命令时末尾没有 & 会要求输入密码。有什么问题吗?

linux sudo
4个回答
19
投票

你可以跑

sudo bash -c 'synaptic &'


13
投票

sudo --help 关于选项 -b 的说明

-b, --background              run command in the background

这对我有用

sudo -b su -c "command what you want to run"

5
投票

问题在于

sudo
命令本身正在后台运行。因此,当它尝试访问标准输入来读取密码时,它将被停止(SIGSTOP)。

一个简单的解决方案是创建一个 shell 脚本来运行

synaptic &
,然后在前台运行
sudo
脚本(即没有
&
)。


0
投票

根据之前的答案,仅将

-b
添加到以
sudo
开头的命令可能会起作用,如下所示:

sudo -b COMMAND

适用于以下命令:

sudo -b mongod --config /etc/mongod.conf

注意。对于非 sudo 命令,有 nohup,如下:

nohup COMMAND &

在命令前添加

nohup
,在命令后添加
&
可能适用于非
sudo
命令。

© www.soinside.com 2019 - 2024. All rights reserved.