OK, from what you've posted 'till now, the basic structure would be something like this (pseudo-code)
Code:
Read numbers from file
Process them
Create output files
Create array of commands to run
Total processes=0
While there are commands left
pop a command from the stack
fork() a subprocess
In the child
system() the command
In the parent
Total processes++
If total processes >= 4
wait() until any process returns