Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First, I'm not sure that simply settings <code>argv[0]</code> in a C program portably changes the name shown in <code>ps</code>. Maybe it does in some unixen, but my understanding is that it's not expected to.</p> <p>Second, since Windows is specifically non-POSIX compliant, only a few things are "portable" between POSIX and non-POSIX. Since you specifically say 'ps', I'll assume that POSIX is your priority and Windows may not work.</p> <p>More importantly, my understanding of changing <code>argv[0]</code> is that it requires a call to <code>exec</code> to make these changes. Specifically, the <code>exec</code> call has both a path to an executable and a separate <code>argv</code> list. Making your own call allows you to break the shell convention of putting the executable name in <code>argv[0]</code>.</p> <p>You have <a href="http://docs.python.org/library/os.html#process-management" rel="nofollow noreferrer">OS library process management</a> which gives you direct access to the OS library for doing this. You should consider breaking your script into two parts -- a starter and the "real work". The starter establishes the run-time environment and exec's the real work with the desired parameters. </p> <p>In C, you're replacing your own process with another. In Python, you're replacing the old Python interpreter with a new one that has a different argv[0]. Hopefully, it won't balk at this. Some programs check argv[0] to decide what they're doing.</p> <p>You also have <a href="http://docs.python.org/library/subprocess.html#subprocess.Popen" rel="nofollow noreferrer">subprocess.popen</a> that you can use to set your desired args and executable. In this case, however, the parent process should lingers around to collect the child when the child finishes. The parent may not be doing anything more than a <code>Popen.wait</code></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload