Difference between revisions of "File descriptors"

From Hackepedia
Jump to navigationJump to search
Line 4: Line 4:
  
 
There are a number of ways to see the open file descriptors of another program.  In BSD the fstat(1) command lists all running programs (processes) of the system and their open descriptors furthermore it lists what type of descriptor it is (file, socket, pipe, etc) and tries to give a hint of what the descriptor is reading or writing on such as what filesystem and what inode number on that file system.  In [[OpenBSD]] network sockets display what port number they have open which is useful for finding the program of that port.
 
There are a number of ways to see the open file descriptors of another program.  In BSD the fstat(1) command lists all running programs (processes) of the system and their open descriptors furthermore it lists what type of descriptor it is (file, socket, pipe, etc) and tries to give a hint of what the descriptor is reading or writing on such as what filesystem and what inode number on that file system.  In [[OpenBSD]] network sockets display what port number they have open which is useful for finding the program of that port.
 +
 +
 +
----
 +
 +
In [[Linux]] you'd use lsof or dig through the /proc filesystem to see open descriptors.

Revision as of 11:23, 5 October 2005

A file descriptor is a handle in a program that allows data to be read and written. It is assigned a number starting at 0 and going to the file descriptor limit. A descriptor of -1 indicates an error. When a new process is created (by means of the fork(2) system call) it inherits all open file descriptors from the parent process. New file descriptors are made by the following system calls open(2), pipe(2), and socket(2). A descriptor can be duplicated thus creating a new descriptor and number with the dup(2) system call. A descriptor can be destroyed by means of the close(2) system call. All programs executed from a shell have the following 3 descriptors open bound to the terminal: Stdin, Stdout and Stderr, representing descriptor numbers 0, 1 and 2 respectively. More about descriptors can be found in the fd manpage on the OpenBSD system; "man 4 fd" to see this.


There are a number of ways to see the open file descriptors of another program. In BSD the fstat(1) command lists all running programs (processes) of the system and their open descriptors furthermore it lists what type of descriptor it is (file, socket, pipe, etc) and tries to give a hint of what the descriptor is reading or writing on such as what filesystem and what inode number on that file system. In OpenBSD network sockets display what port number they have open which is useful for finding the program of that port.



In Linux you'd use lsof or dig through the /proc filesystem to see open descriptors.