If you really wanted to do IPC between processes just to count directories, though, shared memory beats pipes IMO. mmap() an anonymous segment, and each fork()ed process will have access to it. ...
If it's saying bad file descriptor it probably means it. Without seeing your actual code, I can't tell why you're closing a bad file descriptor, you should print the FD's to stderr when you open a...