in reply to Exec command running in background after a fork

Hmmm ,

The problem would appear to be that you spawned a child, told it to go away and do something and then neglected to hang around waiting for your child to finish e.g.

. . } else { # parent print "forked child \$pid= $pid\n"; wait(); # Added exit 0; } . .

A user level that continues to overstate my experience :-))