Subject: RE: Time sharing and fork
From: Bernard Dautrevaux <[email-masked]>
To: "'Stephane Corbe'" <[email-masked]>, [email-masked]
Cc: [email-masked]
Date: Mon, 25 Mar 2002 14:46:39 +0100

> -----Original Message-----
> From: Stephane Corbe [mailto:[email-masked]]
> Sent: Friday, March 22, 2002 4:55 PM
> To: [email-masked]
> Cc: [email-masked]
> Subject: Re: Time sharing and fork
> 
> 
> Christopher Faylor wrote:
> 
> > That's not guaranteed fork behavior.  If the child never 
> started, that would
> > be a bug.
> 
> As you can see in my previous post, the programm is really simple :
> a loop of printf for the child, a loop of printf for the father.
> There's no place for a bug here ...

And there's no bug either in the result you got :-)

> 
> >  There is no guaranteed behavior with respect to which process is
> > scheduled after a fork on windows or linux.  If you want to 
> serialize things
> > use one of the wait calls.
> 
> I don't want serialized anything, I don't expect that the 
> child or the father
> start at first.

So what is your problem?

> 
> Just I wish that the child share the time (the cpu) with his father.

Except that if the child (or the father) uses all available processor time,
then as long as it runs there is no time to left to the father. What an OS
tries to do here is to give you th emost effective result, that is the
shorter total execution time. It would switch only if it thinks it's
beneficial, i.e. for example if there is contention of the output, that is
if you write on a low speed output device: the chile write some, get
blocked, then the father start, the output drains during startup time (it's
probably handled in interruption), then th efather can output some before
being blocked, then the son restarts, etc. etc. ad nauseam :-)

> 
> On solaris the two processes run like that :
> (A is some printf from father, B is some printf from child)
> 
> ABABABABABABA(end of A)B(end of B)
> 
> On cygwin I have this result :
> 
> AAAAAAA(end of A)BBBBBBB(end of B)
> 

Both are perfectly fitting the requirements written by your program: you
want some number of As *and* some number of Bs and do not give *any*
constraint regarding th eorder in which you want the As and Bs to get out.
If you *need* some constraints then you have to use synchronization
primitives...

HTH

        Bernard

--------------------------------------------
Bernard Dautrevaux
Microprocess Ingenierie
97 bis, rue de Colombes
92400 COURBEVOIE
FRANCE
Tel:	+33 (0) 1 47 68 80 80
Fax:	+33 (0) 1 47 88 97 85
e-mail:	[email-masked]
-------------------------------------------- 

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/