更改 Mac/Linux 上进程的用户所有者?
我有一个以 root 身份运行的程序。该应用程序调用另一个程序(processA)来运行。当 processA 运行时,它由 root 拥有,但我希望它的所有者是当前登录的用户。怎么做呢?
I have a program that is running as root. This app calls another program (processA) to run. When processA is running, it is owned by root but I want owner of it to be the current user logged on. How to do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,这有点棘手......取决于它是守护进程(服务)还是运行此命令/应用程序。
对于第二种情况,您可以使用“su”命令。
这是一个简短的例子。
1.我创建了一个包含以下内容的简单脚本(它将在后台休眠 100 秒,并输出与该脚本对应的进程列表):
2。我像这样运行“su”命令(我当前以“root”身份登录,我想以“沙箱”用户身份运行此脚本):
sandbox = 将运行此命令的用户名。
-c ./test.sh = 表示将执行此命令
3。输出(第一列=拥有此进程的用户):
我希望它会有所帮助,
斯特凡
Well it's a little bit tricky... Depends if it's a daemon (service) or you run this command/app.
For the 2nd case you can use "su" command.
Here's a short example.
1. I create o simple script with following content (it will sleep in background for 100 seconds and will output the process list coresponding to this script):
2. I run the "su" command like this (I'm currently logged in as "root" and I want to run this script as "sandbox" user):
sandbox = the username that will run this command.
-c ./test.sh = means it will execute this command
3. Output (first column = the user that owns this process):
I hope it will help,
Stefan