2

I am trying to create multiple processes using fork() and execvp() calls, but so far I've been unsuccessful. Here is what I am trying to do:

Processes A, B, C should run at the same time. When they are finished, process D should run. When it is done, processes E and F should run.

I can call execvp() successfully by passing the program name and its arguments, but I don't know how many times I should call fork() and where. I also know how to call wait(), but again I am not sure where it should be called.

How would I do this?

skaffman
  • 398,947
  • 96
  • 818
  • 769
user246392
  • 2,661
  • 11
  • 54
  • 96

1 Answers1

0

I would approach this in the following manner:

  1. Main Program starts -> fork() Process A, wait() for completion
  2. Process A starts -> fork() Process B, run code, wait() for Process B completion
  3. Process B starts -> fork() Process C, run code, wait() for Process C completion
  4. Process C starts -> runs code, returns to Process B
  5. Process B returns to Process A
  6. Process A returns to Main Program
  7. Main Program continues to run, calls Process D routines (without forking)
  8. Main Program -> fork() Process E, wait() for completion
  9. Process E starts -> fork() Process F, run code, wait() for Process F completion
  10. Process F starts -> runs code, returns to Process E
  11. Process E returns to Main Program
Seth
  • 2,683
  • 18
  • 18