Change owner of a currently running process

左心房为你撑大大i 提交于 2020-02-28 06:45:30

问题


I have a process that is currently running with pid, $PID, and owned by the user foo which is not root. I want to transfer the ownership of this process to another user bar which is also not root.

Is there a shell command that changes the owner of a process? I'm thinking of a chown but for processes that looks something like.

chownproc [option] PID

This question and this question are similar, but not quite what I'm looking for and chown man pages doesn't say anything about processes, only files.

If there isn't, is there a reason why this hasn't been done or isn't possible?


回答1:


You cannot do that, there's no such syscall. However, depending on how you want to affect the process, you could try some hack if the process is not critical to your system.

(gdb) attach process_id
(gdb) call putenv ("UID=1234")
(gdb) call putenv ("EUID=1234")
(gdb) call putenv ("GID=1234")
(gdb) detach

Note that this WILL NOT WORK:

(gdb) call setuid(1234)

This does not really answer to your question (change the owner of a running process), but considering that you may want to change the owner to affect something about the process, maybe this hack help.

Remember that it's very likely that this breaks your process.

(based on this: Is there a way to change another process's environment variables?)



来源:https://stackoverflow.com/questions/37401774/change-owner-of-a-currently-running-process

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!