Firstly, I'm not sure that just setting argv[0] in a C program will change the name displayed in ps . Perhaps this happens on some unixen, but I understand that this is not expected.
Secondly, since Windows is not specifically compatible with POSIX, only a few things are "portable" between POSIX and non-POSIX. Since you specifically say “ps”, I assume POSIX is your priority and Windows may not work.
More importantly, my understanding of the argv[0] change is that exec calls are required to make these changes. In particular, the call to exec has both a path to the executable file and a separate argv list. Making your own call allows you to break the shell convention of sending an executable name to argv[0] .
You have an OS library process control that gives you direct access to the OS library for this. You should consider hacking the script into two parts - the starter and the “real job”. The starter sets up the runtime and does the real work with the required parameters.
In C, you replace your own process with another. In Python, you replace the old Python interpreter with a new one that has another argv [0]. I hope this will not happen. Some programs check argv [0] to decide what they are doing.
You also have subprocess.popen , which you can use to set the desired arguments and executables. In this case, however, the parental process must be delayed in order to assemble the child when the child is finished. Parent can do nothing more than Popen.wait
S.Lott Feb 19 '09 at 11:31 2009-02-19 11:31
source share