a new kind of "destroy action" needed to prevent zombies 
Author Message
 a new kind of "destroy action" needed to prevent zombies

I was recently writing a little pop-11 utility that could be given a
unix command and would produce a line repeater for the output of the
command. (I'll send the code in my next message.)

Under Unix, this kind of thing easily creates zombies (sub-proceses that
don't die because their parent process has not "waited" for them).

So I fixed the repeater to call syswait if it had got to the end
of its output.

However, the user program could read some lines of output to get what it
needs and then not read to the end. In that case the zombie would
remain until the Poplog process died.

This sort of thing made me realise that it would be quite useful to have
a new version of syspipe which took an optional extra argument, a
reference, which, if it contained an integer would be assumed to contain
the process id (pid) of a child process.

In that case syspipe would create a pipe with an associated destroy
action such that if ever that pipe was garbage collected the destroy
action would use syswait to "wait" for the child. Then, for example lib
pipein would be defined something like this.

define global pipein(command, args, flag) -> result;
;;; Spawn a process to run the command with args.
;;; Return either a readable device or a character repeater, for the
;;; output of the process. If -flag- is false return the device.
        lvars command, args, flag, din, dout, result;

    lvars child_info = consref(false);

        ;;; Make the pipe.
        syspipe(if flag then true else "line" endif, child_info) -> din -> dout;

        if sysvfork() ->> pipein_child_pid then
        ;;; in parent process

        ;;; put child pid into the reference
        pipein_child_pid -> cont(child_info);

                ;;; Prepare to get characters from pipe
                if flag then discin(din) else din endif -> result
                ;;; In child process - execute the command to produce the output
                dout -> popdevout;
                dout -> popdeverr;   ;;; ensure you get error messages
                sysexecute(command, args, false);
                mishap(command,args,2,'PIPEIN: Command not found ??');

Note the extra argument to syspipe.

NB this won't work in current Pop-11.

If this sort of thing were supported then it would not be necessary
for user programs to call syswait to prevent zombies. It would be
a side effect of a garbage collection, which would typically happen
not long after the pipe was no longer in use.


PS I wonder if this will make it through the popforum news -> email
Aaron Sloman,
School of Computer Science, The University of Birmingham, B15 2TT, England

Phone: +44-(0)21-414-3711       Fax:   +44-(0)21-414-4281

Wed, 25 Oct 1995 08:19:34 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Advice needed to prevent "handle" death

2. ANNOUNCE: new "plus"- and "dash"-patches available for Tcl7.5a2/Tk4.1a2

3. zombie processes using "after"

4. Creating special kind of "application"?

5. Help with "Action"

6. Template Question on "Action Tab"

7. "Iterating Several Actions"

8. prevent "beep" when press alt-a

9. Replacing "Shutdown" Action Button in LaunchPad

10. Bryan Schofield's "Action" package

11. Better ways of expressing "KIND"

12. A question about "kind"?


Powered by phpBB® Forum Software