> I've had this problem too, I have yet to resolve it. You could start by tossing the very first and totally superfluous "else". to simplify things.
Then, it would be tempting to take the dup(fd,0); close(fd); out to before the if(pid==0)... Well spotted, Kenji. Let's hope my shot in the dark is half as good :-) Lucio.