Why does setting `ulimit -n` from a Go program on Linux 32-bit distributions result in an \'invalid argument\' error?

DDD
Release: 2024-11-03 06:51:02
Original
862 people have browsed it

Why does setting `ulimit -n` from a Go program on Linux 32-bit distributions result in an

How to set ulimit -n from a Go program?

Problem

A user attempted to set ulimit -n from within a Go program to restrict it within the program rather than globally, using the setrlimit and getrlimit system calls. However, an error occurred when trying to set the value, stating "invalid argument."

Solution

It was discovered that the issue was due to Go bugs in Getrlimit and Setrlimit for Linux 32-bit distributions. These bugs have since been fixed, and the following steps can be taken to resolve the problem:

  1. Update to the Go default branch tip. This will include the bug fixes.
  2. Rebuild the program using the updated Go version.

Results

After updating to the Go default branch tip and rebuilding the program, the expected behavior is observed:

$ ./rlimit
{1024 4096}
Error Setting Rlimit  operation not permitted
Rlimit Final {1024 4096}
$ sudo ./rlimit
[sudo] password for peterSO: 
{1024 4096}
Rlimit Final {999999 999999}
Copy after login

Note: For Linux/amd64 distributions, the issue was not encountered. The problem was specific to Linux 32-bit distributions.

The above is the detailed content of Why does setting `ulimit -n` from a Go program on Linux 32-bit distributions result in an \'invalid argument\' error?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template