【问题标题】:change user owner of process on Mac/Linux?在 Mac/Linux 上更改进程的用户所有者?
【发布时间】:2011-12-29 18:21:56
【问题描述】:

我有一个以 root 身份运行的程序。这个应用程序调用另一个程序(processA)来运行。当 processA 运行时,它归 root 所有,但我希望它的所有者是当前登录的用户。怎么做?

【问题讨论】:

    标签: macos process owner


    【解决方案1】:

    这有点棘手...取决于它是守护程序(服务)还是您运行此命令/应用程序。

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

    1.我创建了一个包含以下内容的简单脚本(它将在后台休眠 100 秒,并输出与该脚本对应的进程列表):

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

    2。我像这样运行“su”命令(我目前以“root”身份登录,我想以“sandbox”用户身份运行此脚本):

    su - sandbox -c ./test.sh
    

    sandbox = 将运行此命令的用户名。 -c ./test.sh = 表示会执行这个命令

    3.输出(第一列 = 拥有此进程的用户):

    root@i6:/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
    root@i6:/web-storage/sandbox#
    

    希望对你有帮助 斯蒂芬

    【讨论】:

    • @Stefan:这对我来说很棒。我已经尝试过并且成功了。非常感谢。
    • 欢迎:)!我很高兴你成功了!
    猜你喜欢
    • 2010-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-25
    • 2016-09-20
    • 2014-03-23
    • 1970-01-01
    • 2020-05-20
    相关资源
    最近更新 更多