Re: fork ???

On Fri, Jul 14, 2000 at 02:17:01PM -0700, Sri Ramkrishna wrote:
> >        Under Linux, vfork is merely an alias for fork.
> Oh yeah..I remember that!  I guess if your programming for Linux it
> doesn't matter. :-)

On any modern Unix, fork() is very efficent.  It does not copy
memory more than it needs to, despite the appearance that it
copies the entire parent process.  Unix is *designed* for fast forking.

Howver, when using fork() in a gnome process, there are things to
remember, some of which are covered in Havoc Pennington's excellent
book... some of which you'll find in Marc Rochkind, Advanced Unix
Programming, Richard Stevens' book with the same (or similar) name,
or other places...

* reset all signals
* close open files
* reset any "atexit" handlers if you are not going to call exec
* reset any changed environment variables (this is unusual) or
  use execve() and pass a new environment

In general, it's easier to do
    system("command &");
then use fork();

Be especially careful if you have a signal handler that can call
any X functions -- in general, don't do this -- is the signal
might go off in the child process between the fork() and the exec().
therefore, you should ignore/unset such signals before the fork().

Liam Quin - Barefoot in Toronto - -
Ankh on
Co-author, The XML Specification Guide, Wiley, 1999
Forthcoming: The Open Source XML Database Toolkit

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]