[Python-Dev] Pondering some changes to python.c...

Sean Reifschneider jafo@tummy.com
Mon, 8 Apr 2002 15:05:23 -0600


On Mon, Apr 08, 2002 at 04:51:57PM -0400, Guido van Rossum wrote:
>When I run a Python script that has a #! directly, ps doesn't show me
>the "python" part -- only the script name.  This is in Linux (Red Hat
>7.2).  Maybe it's different for you?

I was told at one point that "#!/usr/bin/env python" was the preferred
she-bang incantation.  However, calling it directly on my 7.2 box seems to
show Python in either case:

   guin:tmp$ printf '#!/usr/bin/python\nimport time; time.sleep(5)' >testscript
   guin:tmp$ ./testscript & ps -awlx | grep testscript
   000   500  8297  6741  10   0  2256 1192 do_sel S    pts/0      0:00 /usr/bin/python ./testscript
   guin:tmp$ printf '#!/usr/bin/env python\nimport time; time.sleep(5)' >testscript 
   guin:tmp$ ./testscript & ps -awlx | grep testscript
   000   500  8300  6741   9   0  2256 1192 do_sel S    pts/0      0:00 python ./testscript

>I'm not sure I understand.  If you have the argc/argv/environ set, why
>do you need to know &argc and &argv?

On Linux and a few other systems, setting the ps string requires re-writing
the block of memory starting at argv[0].  If the data in envp is
allocated next to argv, you can also make use of that (so that you can
write strings longer than "python testscript" in length).

The typical way of doing this involves first making a copy of argv and envp
for the process to continue using, because otherwise argv suddenly becomes
something entirely different than what it originally was.

So, we need to know &argv so that we can hand back the new location.

Sean
-- 
 The important thing is not to stop questioning. Curiosity has its own
 reason for existing.  -- Albert Einstein
Sean Reifschneider, Inimitably Superfluous <jafo@tummy.com>
tummy.com - Linux Consulting since 1995. Qmail, KRUD, Firewalls, Python