Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!haven!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.unix.wizards Subject: Re: Looking for tcsh binary which uses vfork Keywords: tcsh, vfork, SunOS 4.0 Message-ID: <19632@mimsy.UUCP> Date: 16 Sep 89 22:32:39 GMT References: <243@paralogics.UUCP> <10941@smoke.BRL.MIL> <246@paralogics.UUCP> <783@eplunix.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 47 In article <783@eplunix.UUCP> das@eplunix.UUCP (David Steffens) writes: >Take a simple pipe: ``ls | more''. If the 1st process (ls) finishes >_before_ the 2nd process (more) is completely setup, then one gets >the "Stopped (tty ouytput)" message, otherwise not. > >In terms of the source, the palloc() needed to associate the ``more'' >process with the job has not been done by the time that the ``ls'' >process finishes. Then the wait loop in pwait() thinks the _whole_ job >is done and steals the tty out from under the ``more'' process. >Now the ``more'' process gets to run and set itself up, but too late! >This isn't possible w/ vfork because the child _always_ gets to run 1st. This explanation does not hold up, because vfork() does not change this. Csh (and therefore tcsh) must, and presumably does (since it works now), hold SIGCHLD during job creation. If it did not, the following sequence would be possible: csh: vfork child: set up tty pgroup, etc execl("ls") csh: resume; stash process for pwait() ls: read dir, print, exit csh: take signal; pwait() `takes' the whole job so vfork() would not prevent the same problem. As long as SIGCHLD is held, however, we have csh: fork csh: stash process for pwait | child: set up tty pgroup | execl("ls") csh: fork | ls: read, etc | ls: csh: (parent) signal held | csh: (child) execl("more") stash process for pwait | release signal | more: take signal, consume ls exit status; continue waiting for rest of pipeline Here the actual order of things happening in the child process is irrelevant (provided, of course, that one fixes the tty pgroup race). -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris