title: Why could create socketchannels more than max open files?
body: <p>In linux Socket also is a  file, so if exist too many sockets at a time and  more than max open files, it will throw  below exception:</p>
  
  <pre><code>java.net.SocketException: Too many open files
  at sun.nio.ch.Net.socket0(Native Method)
  at sun.nio.ch.Net.socket(Net.java:423)
  at sun.nio.ch.Net.socket(Net.java:416)
  at sun.nio.ch.SocketChannelImpl.&lt;init&gt;(SocketChannelImpl.java:104)
  at sun.nio.ch.SelectorProviderImpl.openSocketChannel(SelectorProviderImpl.java:60)
  at java.nio.channels.SocketChannel.open(SocketChannel.java:142)
  </code></pre>
  
  <p>Till now I could understand, but I'm a little confused with below phenomenon. 
  I executed below command in terminal to find max open file number:</p>
  
  <pre><code>$ ulimit -n
  1024
  </code></pre>
  
  <p>But actually I created about 4091 sockets(SocketChannel) by below code:</p>
  
  <pre><code>while(true) {   
      new Thread(new Runnable() {
          public void run() {
              //...
              try {
                  SocketChannel scChannel = SocketChannel.open();
                  scChannel.connect(new InetSocketAddress(hostname, port));
                  ByteBuffer buffer = ByteBuffer.allocate(1024);
                  scChannel.read(buffer);
              } catch (IOException e) {
                  //...
              }                   
          }
      }).start(); 
  }
  </code></pre>
  
  <p>and from console I knew until it created 4091 socketChannel, then it threw above exception:</p>
  
  <pre><code>Start client 4091
  java.net.SocketException: Too many open files
  </code></pre>
  
  <p>4091 is more than 1024, so why is so? The result from ulimit is not real number of max open files?</p>