[ LUGOS ] for( ; ; fork());

Metod Kozelj metod.kozelj na rzs-hm.si
Tor Jan 27 08:41:39 CET 1998


Howdy!

On Mon, 26 Jan 1998, polz wrote:

> >> >while (!fork()) {}
> >> Ne bi - dela samo dokler fork ne vrne 1 - bolje je while(1){fork();};
> >
> >Dela dokler fork vraca nic. To pa se dogaja nonstop.
> To se zgodi samo v polovici primerov - narascanje porabe procesorja je zato 
> linearno,  ne eksponentno.

Daj, preden se kaksno bedarijo napises, preberi si man fork. Tam
explicitno pise takole:

-------->8---------
RETURN VALUE
       On  success,  the  PID of the child process is returned in
       the parent's thread of execution, and a 0 is  returned  in
       the child's thread of execution.  On failure, a -1 will be
       returned in the parent's context, no child process will be
       created, and errno will be set appropriately.
------->8----------

To konkretno pomeni, da childov proces kot rezultat operacije dobi 0,
stars pa PID childa. No ja, lahko reces tudi, da je rezultat 0 v polovici
primerov, ce med 'primere' stejes tako starsevske kot otroske procese.

Peace!
  Mkx




Dodatne informacije o seznamu Starilist