On Wed, 28 Apr 1999, Amol Mohite wrote:

> secodnly in fork, -1 rmeans an error  no -ve value.
> 
> so wo my qs. again, why 0 ?

First off we need to know if our fork was successful so we return a -1 if
it was not.  Then we need to know the pid of the child if we are the
parent, so, why not make that the return value of the fork.  We know all
pids are positive integers so any value greater than 0 could be a pid and
as such you have to treat this entire return range as indication that you
are the parent. Then, allw e are left with is how to tell if we are the
child.  If you'll notice from above, -1 and >0 are already taken so why
not just use 0.  Of course we could use -234 instead of 0 but that would
not be very intuitive and C and UNIX are the two most intuitive
enviroments every and we would not want to break that:)

If my rambling sound exactly as such look at this code and see if that
helps.

if((child_pid=fork())<0){  /* check for an error */
      perror("fork");
      exit(0);
    }else if(child_pid==0){ /* here we are executing child code */
      child(&AcceptS);
    }else{
      AcceptS.Close();
      waitpid(-1,&child_status,WNOHANG); /* here we are executing parent
                                            code were we may need to no
                                            the pid */
    }                                       


    .......  [EMAIL PROTECTED]
     `:::'     Kevin Sivits  .......  ......
      :::  *                  `::.    ::'   
      ::: .::  .:.::.  .:: .::  `::. :'     
      :::  ::   ::  ::  ::  ::    :::.      
      ::: .::. .::  ::.  `::::. .:'  ::.    
    ..:::.....................::'   .::::.

#!/bin/perl -sp0777i<X+d*lMLa^*lN%0]dsXx++lMlN/dsM0<j]dsj
$/=unpack('H*',$_);$_=`echo 16dio\U$k"SK$/SM$n\EsN0p[lN*1
lK[d2%Sa2/d0$^Ixp"|dc`;s/\W//g;$_=pack('H*',/((..)*)$/)

Please visit http://online.offshore.com.ai/arms-trafficker/     

Reply via email to