exec* exiting?

Andrew Dalke dalke at dalkescientific.com
Mon Aug 20 16:02:27 EDT 2001


Martelli-bot:
>:On good Unix-ish implementations, your process's memory is
>:only duplicated 'virtually', with copy-on-write.  It's therefore
>:no big issue to fork "a process which uses a lot of memory".

Mats Wichmann:
>Yup, [...] If the very next thing you
>do is "exec" the cost is not terribly high.

I've been worried about popen2.Popen3.__init__

        self.pid = os.fork()
        if self.pid == 0:
            # Child
            os.dup2(p2cread, 0)
            os.dup2(c2pwrite, 1)
            if capturestderr:
                os.dup2(errin, 2)
            self._run_child(cmd)

    def _run_child(self, cmd):
        [...]
        try:
            os.execvp(cmd[0], cmd)
        finally:
            os._exit(1)

In this case, what's the fork/exec overhead?  Various
pages are modified (eg, incref/decrefs to None, 0, 1, 2
and various variables; a change to the stack, a getitem).
Do OSes these days only modify-on-write parts of the
process or does a modification to only a part require
copying the whole things.

(Hard to grep through my paper copy of the Minux source,
and that's probably out of date anyway:)

                    Andrew






More information about the Python-list mailing list