0

I'm expecting my fork() to allow my child processes to print where they are in the loop to test my round robin scheduling algorithm, but the count is never printed. More specifically, the parent process executes all and I never see a print from my child. Any ideas why? I might be misunderstanding the use of fork() or wait() still.

for (i = 0; i < 64; i++)
  {
    pid = fork();
    if (pid < 0) {
      cprintf("fork failed\n");
      return -1;
    } else if (pid > 0) {
      cprintf("Parent: child process has pid: %d\n", pid);
      wait();
      cprintf("Parent: child process %d has completed\n", pid);
    } else if (pid == 0) {
      for (int n = 0; n < 1000; n++)
      {
        cprintf("Child: this child is at %d in the loop", n);
      }
      exit();
    }
}

Thanks.

EDIT: The output is as follows

$ testscheduler
Test Scheduler

Round Robin Test
Parent: child process has pid: 4
Parent: child process 4 has completed
Parent: child process has pid: 5
Parent: child process 5 has completed
Parent: child process has pid: 6
Parent: child process 6 has completed
Parent: child process has pid: 7
Parent: child process 7 has completed
Parent: child process has pid: 8
Parent: child process 8 has completed
Parent: child process has pid: 9
Parent: child process 9 has completed
Parent: child process has pid: 10
Parent: child process 10 has completed
Parent: child process has pid: 11
Parent: child process 11 has completed
...
...
...
Parent: child process has pid: 66
Parent: child process 66 has completed
Parent: child process has pid: 67
Parent: child process 67 has completed
Cody Berry
  • 263
  • 3
  • 14

1 Answers1

0

Your user mode program seems to work.

I would suspect your modified scheduling algorithm, please edit your post with more information.

Omer Efrat
  • 295
  • 1
  • 5