how to spawn a process under different user

S

sanket

Hello All,

I am trying to use python's subprocess module to launch a process.
but in order to do that I have to change the user.

I am not getting any clue how to do that?
so can anyone please tell me How can I spawn a process under different
user than currently I am logging in as.

Thank you,
sanket
 
T

Tim Golden

sanket said:
Hello All,

I am trying to use python's subprocess module to launch a process.
but in order to do that I have to change the user.

I am not getting any clue how to do that?
so can anyone please tell me How can I spawn a process under different
user than currently I am logging in as.

What platform are you on? If you are on Windows,
there was a thread on this subject some time in
the last month. (Short answer: switching user before
launching subprocess won't work; switching within
the subprocess will...)

TJG
 
S

sanket

What platform are you on? If you are on Windows,
there was a thread on this subject some time in
the last month. (Short answer: switching user before
launching subprocess won't work; switching within
the subprocess will...)

TJG

Hi TJG,
Thanks for the reply.

I am using python 2.4 on centos.

Thanks,
sanket
 
G

Gabriel Genellina

I have never done this in python; but, using the normal system calls in C
the process is basically:

1. fork() a new process
2. the child process changes its user id with setreuid() and
possibly its group id with setregid()
3. then the child exec()s new process which replaces itself

All of the necessary functions should be under the os module on POSIX
operating systems.

How to do that using the subprocess module: write a function for item (2)
above and pass it as the preexec_fn argument to Popen. preexec_fn is
executed after fork() and before exec()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top