*BSD News Article 1819


Return to BSD News archive

Xref: sserve comp.lang.c:29896 comp.sources.wanted:12725 comp.unix.misc:4270 comp.unix.questions:24110 comp.sys.apollo:12456 comp.unix.bsd:1852
Newsgroups: comp.lang.c,comp.sources.wanted,comp.unix.misc,comp.unix.questions,comp.sys.apollo,comp.unix.bsd,uiowa.comp.apollo
Path: sserve!manuel!munnari.oz.au!uniwa!cujo!marsh!chans
From: chans@marsh.cs.curtin.edu.au (Sean Chan)
Subject: Re: Fork ?
Message-ID: <chans.710389620@marsh>
Sender: news@cujo.curtin.edu.au (News Manager)
Organization: Curtin University of Technology
References: <1992Jul6.005853.21925@news.uiowa.edu>
Date: Mon, 6 Jul 1992 02:27:00 GMT

Referenced from "A Book On C : Programming in C" by Kelley, A. and I.
Pohl (2nd edition). Benjamin/Cummings 1990

pg. 426-427
fork - used to create a new process, the child process, that runs
       concurrently with the parent process. Its unique to UNIX and is
       not a part of ANSI.

eg.
#include <stdio.h>
#include <time.h>

main ()
{
   int fork (void),
       fib (int);
   void sleep (unsigned);

   if (fork () == 0)
      for (i = 0; i < 30; ++i)
        printf ("fib(%2d) = %d\n", i, fib(i));
   else
      for (i =0; i < 30; ++i) {
        sleep (2);
        printf ("elapsed time = %d\n", time (NULL) - begin);
   }
}

int fib (int n)
{
 if (n <= 1) 
    return n;
 else
   return (fib (n-1) + fib (n - 2));
}

Hope this helps...

Sean Chan
chans@marsh.cs.curtin.edu.au
pchans@cc.curtin.edu.au