When child processes are created using the fork system call what is there scheduling priorities..are they same? if so will always a child process run first and then parent...or is there a manipulation to this pattern.

I have a implementation which apparently is running the parent process first. Is this expected?


Please be careful to understand that priority is not the same as order of running. As a rule, when you fork a process it runs at the same priority, unless you ask for it to be lower. The order in which parent and child run is separate.

The answer is that you cannot and should not depend on the order. In many cases after forking (or using any comparable mechanism in any other operating system), the parent will continue to run before the child starts. Or not. It all depends.

If it is important, you will have to include synchronising mechanisms to control which process runs and which waits.

| improve this answer | |
  • 3
    +1 if you rely on the order of things, then you're asking for trouble. It's the OS who will decide how the time is shared between the proccesses. This is not language specific. – Vaughan Hilts Mar 29 '14 at 21:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.