Looks like a forking code example (Hope I'm not stating the obvious here). The program should run normally as far as fork at which point the process duplicates itself, both processes continuing from that point. In the parent process "fork" returns the PID of the child, in the child process I think it returns undef. By testing $pid it determines which branch it took, the child branch writes some stuff to a pipe and the parent branch is probably meant to read it.

I've no idea at all what the fcntrl and chmod are for.

There's probably a good reason its laid out like that but personally I'd prefer to do something like