Change owner of a currently running process
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?)
Changing the owner of an existing process in Linux
I am aware of kchuid which does exactly that, and although it appears abandoned, it doesn't look like it would be hard to bring up-to-date.
That said, the hosting company I work for does allow (on the shared hosting packages) users to run their own webserver- including Tomcat- on port 80. This is done using a tool called authbind which doesn't require the server start as root- but simply lets non-root users bind to selected IP addresses and selected ports.
The only catch is that authbind won't work with Java's network abstraction layer by default. You will need to disable Java's IPV6 support, and probably specify a specific IP address to bind to within your application. The former can be done by starting the JRE with -Djava.net.preferIPv4Stack=true
but the latter is application-specific.
change user owner of process on Mac/Linux?
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):
#!/bin/bash
sleep 100 &
ps faux | grep test.sh
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):
su - sandbox -c ./test.sh
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):
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#
I hope it will help,
Stefan
Changing user process on a system process
You can not change users a process is running under, you may be able to do impersonation to run a section of code as another user, but you can not modify the process itself to be running as another user.
To make your process run as SYSTEM it must be started under that user.
How to change the terminal title to currently running process?
UPDATE: my previous answer (below) displays the previous command in the title bar.
Ignoring everything from my previous answer and starting from scratch:
trap 'echo -ne "\033]0;${PWD}: (${BASH_COMMAND})\007"' DEBUG
Running the following at the command prompt:
$ sleep 10
The window title bar changes to /my/current/directory: (sleep 10)
while the sleep 10
is running.
Running either of these:
$ sleep 1; sleep 2; sleep 3
$ { sleep 1; sleep2; sleep 3; }
The title bar changes as each sleep
command is invoked.
Running this:
$ ( sleep 1; sleep 2; sleep 3 )
The title bar does not change (the trap
does not apply within a subprocess call).
One last one:
$ echo $(sleep 3; echo abc)
The title bar displays (echo $sleep 3; echo abc))
.
previous answer
Adding to this answer:
store_command() {
declare -g last_command current_command
last_command=$current_command
current_command=$BASH_COMMAND
return 0
}
trap store_command DEBUG
PROMPT_COMMAND='echo -ne "\033]0;${PWD}: (${last_command})\007"'
Additional reading materials re: trap / DEBUG
:
- bash guide on traps
- SO Q&A
PHP - changing ownership of a process while running
You can change user/group ids with the following functions:
posix_setgid
posix_setuid
posix_setegid
posix_seteuid
If you need to change the group, you'll want to perform that first.
Related Topics
Question About Zombie Processess and Threads
Tar Command Not Found in Dockerfile
How to Paste from Buffer in Ex Mode of Vim
Linux - Run Process on Several Cores
Haskell Cabal: Mysterious Missing or Recursive Dependencies
Building Helloworld C++ Program in Linux with Ncurses
Intel Msr Frequency Scaling Per - Thread
Change Owner of a Currently Running Process
Exploiting a String-Based Overflow on X86-64 with Nx (Dep) and Aslr Enabled
When Will Send() Return Less Than The Length Argument
64-Bit Linux, Assembly Language, Issues
Redirecting Stdout & Stderr from Background Process
Installing 32 Bit Libraries (Glibc) on 64 Bit Rhel Without Using Yum