file descriptor | /proc/*/fd

jenkins@ubuntu:/proc/78010/fd$ ls -lar
total 0
lrwx------ 1 jenkins jenkins 64 Jul 15 03:33 2 -> /dev/pts/19
lrwx------ 1 jenkins jenkins 64 Jul 15 03:33 1 -> /dev/pts/19

lrwx------ 1 jenkins jenkins 64 Jul 15 03:33 0 -> /dev/pts/19


file descriptor is an opaque handle that is used in the interface between user and kernel space to identify file/socket resources. Therefore, when you use open() or socket() (system calls to interface to the kernel), you are given a file descriptor, which is an integer (it is actually an index into the processes u structure - but that is not important). Therefore, if you want to interface directly with the kernel, using system calls to read()write()close() etc. the handle you use is a file descriptor.
When a process makes a successful request to open a file, the kernel returns a file descriptor which points to an entry in the kernel's global file table. The file table entry contains information such as the inode of the file, byte offset, and the access restrictions for that data stream (read-only, write-only, etc.).
File descriptor diagram

Stdin, stdout, and stderr

On a Unix-like operating system, the first three file descriptors, by default, are STDIN(standard input), STDOUT (standard output), and STDERR (standard error).
0 - stdin
1 - stdout
2 -stderr

Creating file descriptors[edit]

  • open()
  • creat()
  • socket()
  • accept()
  • socketpair()
  • pipe()
  • opendir()
  • open_by_handle_at() (Linux)
  • signalfd() (Linux)
  • eventfd() (Linux)
  • timerfd_create() (Linux)
  • memfd_create() (Linux)
  • userfaultfd() (Linux)

Comments

Popular posts from this blog

HAproxy logging

tomcat catalina coyote jasper cluster

NFS mount add in fstab _netdev instead of default | firewall-cmd --list-all