packetie
packetie

Reputation: 5069

increase limit within a program

I have a C program on Ubuntu. This program needs to open a lot of files. So I have to run it as the following:

ulimit -n 10000; ./xyz

Wonder if there is a way to do something within the program xyz itself to increase the limit. The program runs as root user, so it has the necessary privilege. In the C program (source code), I called

system("ulimit -n 10000");

But it doesn't work, which is not surprise.

Upvotes: 0

Views: 51

Answers (2)

Oldest Software Guy
Oldest Software Guy

Reputation: 741

See getrlimit(2)

Consider using the getrlimit(2) and setrlimit(2) routines. Note that only a process running with superuser privilege can increase a limit; any user can reduce their resource limits.

Upvotes: 1

Thomas Nguyen
Thomas Nguyen

Reputation: 494

why not write a wrapper?

xyz_wrapper.sh

ulimit -n 10000; ./xyz

then simply run the wrapper

./xyz_wrapper.sh

Upvotes: 0

Related Questions