Re: [CODE] Splitting off a seperate process?

From: Daniel A. Koepke (
Date: 06/08/01

On Fri, 8 Jun 2001, Pure Krome wrote:
> Part of the code includes writing something to a file (yes, each time
> the function is called).

First, check, recheck, think through, and rethink your particular design
for this matter.  You didn't say why you were doing this, so, naturally, I
can't help you with that part of the equation.  Fact is, writing 100s of
structures out to a file very frequently is a bad idea.  That you feel its
necessary might be indicative of bad design.  So make sure you've got the
right design before you try to optimize an implementation of a bad design.
This is a fundamental rule of programming.  It can be summarized as such:

  If you think others will doubt your design, then you should doubt it
  before they ever see it.

Even if you end up keeping the design, looking at it from this perspective
means you are better suited to assuage another's skepticism over the

> What i was hoping to do, was to call that function as a seperate
> process? Is this forking? If so, can i do this function completly
> seperate from the game loop so it doesn't effect the game?

Yes, this is forking.  You would do something akin to:

  void foobar(FILE *fp)
    pid_t child = fork();

    if (child > 0) {
      /* Parent returns back to child. */

    /* In the child process (or the only process if we failed to fork). */
    . /* do the writing here */

    if (child) {
      /* We failed to fork, report the error and return. */

     * Said the father to the child: I brought you into this world, I
     * sure as hell can take you out of it.

Any decent book on UNIX describes this stuff in full detail, so go book
shopping if you're really in need of more.

Daniel A. Koepke (dak),
Caveat emptor: I say what I mean and mean what I say.  Listen well.
Caveat venditor: Say what you mean, mean what you say.  Say it well.

   | FAQ: |
   | Archives: |

This archive was generated by hypermail 2b30 : 12/05/01 PST