I needed a script that launched three instancies of the nmap
network scanner to scan all our network in parallel. Each time
a subnet is scanned and nmap finishes, another instance gets
started to scan another subnet. This way I always have three
parallel processes that do the job.
To learn how to do it I created this small script that could
be a starting point for accomplishing similar tasks. You can substitute the sleep with an exec that runs an external program, for example, or fill that space with any perl you like!
Update: Thanks to other monks' suggestions I added "sanity checks": now the return value from fork and wait is checked. Thanks also to larsen, valdez, abell and alloalex's for their suggestions