title: Golang Getrlimit returns the different value from ulimit
body: <p>I tried to use Golang to get current &quot;open fd&quot; limit with the <code>Getrlimit</code> function, here is my code:</p>
  <pre class="lang-golang prettyprint-override"><code>package main
  
  import (
      &quot;fmt&quot;
      &quot;syscall&quot;
  )
  
  func main() {
      lim := syscall.Rlimit{}
  
      err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &amp;lim)
      if err != nil {
          panic(err)
      }
      fmt.Println(&quot;soft:&quot;, lim.Cur)
      fmt.Println(&quot;hard:&quot;, lim.Max)
  }
  </code></pre>
  <p>Run this will print:</p>
  <pre class="lang-bash prettyprint-override"><code>$ go run main.go
  soft: 1048576
  hard: 1048576
  </code></pre>
  <p>Here you can see the soft number is &quot;1048576&quot;, however, the <code>ulimit -Sn</code> prints it as &quot;1024&quot;. I also tried this with C code:</p>
  <pre class="lang-c prettyprint-override"><code>#include &lt;sys/resource.h&gt;
  #include &lt;stdio.h&gt;
  
  int main() {
      struct rlimit rlim;
      if (getrlimit(RLIMIT_NOFILE, &amp;rlim) == -1) {
          return -1;
      }
      printf(&quot;soft: %lld \n&quot;, (long long) rlim.rlim_cur);
      printf(&quot;hard: %lld \n&quot;, (long long) rlim.rlim_max);
      return 0;
  }
  </code></pre>
  <p>Compile and run it will also print:</p>
  <pre><code>soft: 1024
  hard: 1048576
  </code></pre>
  <p>So the number Golang printed out for the &quot;rlim_max&quot; (hard) is correct, but &quot;rlim_cur&quot; (soft) is incorrect, it's supposed to be &quot;1024&quot;? As you can see both the C code and <code>ulimit -Sn</code> command printed &quot;1024&quot;.</p>
  <p>Here is my testing environment:</p>
  <ul>
  <li>Operating system: Ubuntu 22.04 LTS x86_64</li>
  <li>Golang 1.19.1 for amd64</li>
  </ul>
  <p>I am wondering if anyone experienced the same problem and why it happened like this? Thank you!</p>