2011-11-15 31 views

回答

3

嗯,这有点棘手...取决于它是一个守护进程(服务),或者你运行这个命令/应用程序。

对于第二种情况,您可以使用“su”命令。 这是一个简短的例子。

1.我产生O-简单脚本与以下内容(将在背景睡眠100秒,并且将输出进程列表coresponding此脚本):

#!/bin/bash 
sleep 100 & 
ps faux | grep test.sh 

2.我运行“苏”像这样命令(我目前登录为“根”,我想运行该脚本的“沙箱”的用户):

su - sandbox -c ./test.sh 

沙箱=将运行此命令的用户名。 -c ./test.sh =意味着它将执行此命令

3.输出(第一列=拥有此进程的用户):我希望这将有助于

[email protected]:/web-storage/sandbox# su - sandbox -c ./test.sh 
sandbox 18149 0.0 0.0 31284 1196 pts/0 S+ 20:13 0:00      \_ su - sandbox -c ./test.sh 
sandbox 18150 0.0 0.0 8944 1160 pts/0 S+ 20:13 0:00       \_ /bin/bash ./test.sh 
sandbox 18155 0.0 0.0 3956 644 pts/0 S+ 20:13 0:00        \_ grep test.sh 
[email protected]:/web-storage/sandbox# 

, Stefan

+0

@Stefan:对我来说很棒,我很努力,很成功。非常感谢。 –

+0

欢迎:)我很高兴你成功了! – igniter