Making a popen replacement with vfork()

Stefan Brandle stefan at wheaton.UUCP
Fri May 4 23:04:08 AEST 1990


In article <6830 at jarthur.Claremont.EDU> jseidman at jarthur.Claremont.EDU (James Seidman) writes:
>I'm working on a program which uses popen() several times to run on an
>ULTRIX workstation.  The program's image is very large, occupying almost 50%
>of the computer's core memory.  My problem is that every time a popen()
>occurs, the system grinds to a halt.  What I suspect is happening is that
>popen() calls fork(), fork() tries to copy the entire program image, and
>therefore a lot of swapping has to occur.

vfork might do nicely.  Another possible approach is to have a small stub
program that sets up all necessary pipes, file descriptors, then forks off and
execs the pipe-children and the parent execs the real program you want to run.
That way the program that is getting duplicated would actually be quite small.
This works ok if you have a relatively small number of children and know the
number in advance.  If not, you may need to do it by having a process that acts
as a `daemon' and communicates with your main program by way of sockets or your
favorite IPC method, and gets told by the main program what to popen/fork/exec,
and then sends the results back to the main program.

Of course, if vfork works right, that's an easier solution.

Stefan Brandle
-- 
---------------------------------------------- MA Bell: (708) 260-5019 ---------
Stefan Brandle                  UUCP: ...!{obdient,uunet!tellab5}!wheaton!stefan
Wheaton College			or	stefan at wheaton.UUCP
Wheaton, IL 60187 		"But I never claimed to be sane!"



More information about the Comp.unix.questions mailing list