linuxshellprocesscentos6

Change owner of a currently running process


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?


Solution

  • 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?)