This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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 ...

>  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.

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

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)

Please read again (try?) this really simple programm :

#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>

int main(void)
{
  int probe_pid, i;

    printf("before fork\n");
    probe_pid = fork();
    printf("after fork %d\n", probe_pid);
    switch (probe_pid)
        {
        case 0 :

        for (i=0; i<10000; i++)
        {
          printf("%d> Je suis le fils %d\n", probe_pid, i);
        }
        break;

        case -1 :
          printf ("Erreur fork\n");
          exit(-1);
          break;

        default:

        for (i=0; i<10000; i++)
        {
          printf("%d> Je suis le pere %d\n", probe_pid, i);
        }
        break;
        }
    return 0;
}


--
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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]