-1

After fork() is called, why does the parent process run before the child process in most of the cases? In what scenario will the child process run before the parent process after fork()?

Please explain this to me.

1 Answers1

1

The parent process' fork call is like any other system call in this matter which returns to the application code when done, the process will stop running and will be switched with another process (which might be the child process) due to the preemptive scheduling nature used by XV6 (as well as many other OS). The child process will be run before the parent if the parent's process will end it's time slicing period after starting the handling of the fork system call and before the handling of returning to the application code starts (see the line causes the process to yield at the end of the 'trap' function).

Omer Efrat
  • 226
  • 1
  • 4