in reply to Difference between File Handles and File Descriptors in function parameters.

From my limited experience, filedescriptors ( the actual filehandle numbers) are useful because threads can access any open file under the same pid, via the fileno. Filehandles themselves are just a convenience on top of the file descriptors. See[threads] Open a file in one thread and allow others to write to it and FileHandles and threads. Everytime you open a filehandle, you get a filedesciptor underneath. On linux, you can look at /proc/$pid/fd and see all your filedescriptors sitting right there. You can use this fact to write to all open fd's you own, even from another process.

There may be use also, in passing filedescriptors off to forked processes. You just can't pass a filehandle, but a descriptor yes.

Other uses: to close ALL open filehandles, after having lost track of them. See How to close all open file descriptors after a fork? or the process of Duping filehandles Duping filehandles

So anyways, don't blow off filedescriptors as useless.


I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh
  • Comment on Re: Difference between File Handles and File Descriptors in function parameters.