title: What do /proc/fd file descriptors show?
body: <p>Learning about the <code>/proc/</code> directory today, in particular I'm interested in the security implications of having all the information about a process semi-publicly available, so I wrote a simple program that does some simple whatnot that allows me to explore some properties of the <code>/proc/</code> directory:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;unistd.h&gt;
  #include &lt;fcntl.h&gt;
  
  using namespace std;
  
  extern char** environ;
  
  void is_linux() {
  #ifdef __linux
     cout &lt;&lt; "this is running on linux" &lt;&lt; endl;    
  #endif
  }
  
  int main(int argc, char* argv[]) {
    is_linux();
  
    cout &lt;&lt; "hello world" &lt;&lt; endl;
    int fd = open("afile.txt", O_RDONLY | O_CREAT, 0600);
    cout &lt;&lt; "afile.txt open on: " &lt;&lt; fd &lt;&lt; endl;
  
    cout &lt;&lt; "current pid: " &lt;&lt; getpid() &lt;&lt; endl;;
  
    cout &lt;&lt; "launch arguments: " &lt;&lt; endl;
    for (int index = 0; index != argc; ++index) {
      cout &lt;&lt; argv[index] &lt;&lt; endl;
    }
  
    cout &lt;&lt; "program environment: " &lt;&lt; endl;
    for (char** entry = environ; *entry; ++entry) {
      cout &lt;&lt; *entry &lt;&lt; endl;
    }
  
    pause();
  }
  </code></pre>
  
  <p>Interestingly though (to me anyway), when I check the file-descriptors folder (<code>/pid/&lt;PID#&gt;/fd</code>), I see this:</p>
  
  <pre><code>root@excalibur-VirtualBox:/proc/1546/fd# ls -l
  total 0
  lrwx------ 1 root root 64 Nov  7 09:12 0 -&gt; /dev/null
  lrwx------ 1 root root 64 Nov  7 09:12 1 -&gt; /dev/null
  lrwx------ 1 root root 64 Nov  7 09:12 2 -&gt; /dev/null
  lrwx------ 1 root root 64 Nov  7 09:12 3 -&gt; socket:[11050]
  </code></pre>
  
  <p>why do the file descriptors point to <code>/dev/null</code>? Is that to prevent user's from being able to inject content into a file without actually being the process itself, or am I off base on that? And even more curious, why does the file descriptor to an open file point to a socket? That seems really odd. If anyone can shed some light on this for me, I would really appreciate it. Thanks!</p>