in reply to Problem with Parallel Processes

First of all, you aren't correctly determining the fork fails. If the fork fails, $pid will be undefined. But undef == 0 is a true statement (which will generate a warning, if you have them turned on).

I don't understand the but in couple of seconds, 2 processes exit and remaining 3 processes continue running as normal bit. All the processes are doing are forking, printing, and touching files. I'd expect the entire process, including the children, to be finished within a single second.

Note however that if another user runs this as well, the touch will likely fail (depending on the umask of the original user) - but that shouldn't matter in whether or not the processes fail (and hardly in how fast they are).