コード例 #1
0
    def Start(self):
        """Start this process with fork(), haandling redirects."""
        # TODO: If OSH were a job control shell, we might need to call some of
        # these here.  They control the distribution of signals, some of which
        # originate from a terminal.  All the processes in a pipeline should be in
        # a single process group.
        #
        # - posix.setpgid()
        # - posix.setpgrp()
        # - posix.tcsetpgrp()
        #
        # NOTE: posix.setsid() isn't called by the shell; it's should be called by the
        # login program that starts the shell.
        #
        # The whole job control mechanism is complicated and hacky.

        pid = posix.fork()
        if pid < 0:
            # When does this happen?
            raise RuntimeError('Fatal error in posix.fork()')

        elif pid == 0:  # child
            SignalState_AfterForkingChild()

            # This doesn't make the child respond to Ctrl-Z?  Why not?  Is there
            # something at the Python level?  signalmodule.c has PyOS_AfterFork but
            # it seems OK.
            # If we add it then somehow the process stop responding to Ctrl-C too.
            #signal.signal(signal.SIGTSTP, signal.SIG_DFL)

            for st in self.state_changes:
                st.Apply()

            self.thunk.Run()
            # Never returns

        #log('STARTED process %s, pid = %d', self, pid)

        # Invariant, after the process is started, it stores its PID.
        self.pid = pid
        return pid
コード例 #2
0
    def Start(self, why):
        # type: (trace_t) -> int
        """Start this process with fork(), handling redirects."""
        # TODO: If OSH were a job control shell, we might need to call some of
        # these here.  They control the distribution of signals, some of which
        # originate from a terminal.  All the processes in a pipeline should be in
        # a single process group.
        #
        # - posix.setpgid()
        # - posix.setpgrp()
        # - posix.tcsetpgrp()
        #
        # NOTE: posix.setsid() isn't called by the shell; it's should be called by the
        # login program that starts the shell.
        #
        # The whole job control mechanism is complicated and hacky.

        pid = posix.fork()
        if pid < 0:
            # When does this happen?
            raise RuntimeError('Fatal error in posix.fork()')

        elif pid == 0:  # child
            pyos.SignalState_AfterForkingChild()

            for st in self.state_changes:
                st.Apply()

            self.tracer.SetProcess(posix.getpid())
            self.thunk.Run()
            # Never returns

        #log('STARTED process %s, pid = %d', self, pid)
        self.tracer.OnProcessStart(pid, why)

        # Class invariant: after the process is started, it stores its PID.
        self.pid = pid
        # Program invariant: We keep track of every child process!
        self.job_state.AddChildProcess(pid, self)

        return pid