LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-08-2016, 04:26 PM   #1
fanoflq
Member
 
Registered: Nov 2015
Posts: 397

Rep: Reputation: Disabled
ulimit : changing hard limit


The default ulimit for open files is unlimited.
Once I change it to a lower limit, e.g.

Quote:
[user1@localhost ~]$ ulimit -H -n 2048
[user1@localhost ~]$ ulimit -H -n
2048
Then I try to change it to a higher HARD limit, it would not let me.

Quote:
[user1@localhost ~]$ ulimit -H -n 4096
bash: ulimit: open files: cannot modify limit: Operation not permitted
[user1@localhost ~]$
The only way I can change the hard ulimit to a higher level
is to use /etc/security/limits.conf AND REBOOT!

Quote:
E.g. in limits.conf file:
user1 hard nofile 8192

I cannot use sudo to do hard limit change like so:
$ sudo ulimit -H -n

which gives error.

And when I user su (root) like so:
$ su
<sign it here>
# set ulimit for -n (open files) to 8192:
$ ulimit -H -n 8192

It works, but once I exit su, those changes inside su were no longer valid outside of su.
So it seems su takes me into a new shell!

So how do I change hard limit without changing
/etc/security/limits.conf AND REBOOT in the present shell?

Last edited by fanoflq; 05-08-2016 at 04:32 PM.
 
Old 05-09-2016, 06:33 AM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,702

Rep: Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270
Quote:
Originally Posted by fanoflq View Post
The default ulimit for open files is unlimited.
Once I change it to a lower limit, e.g.



Then I try to change it to a higher HARD limit, it would not let me.



The only way I can change the hard ulimit to a higher level
is to use /etc/security/limits.conf AND REBOOT!
First, reboot isn't necessary. Just logout and login again. The new limits will be set.

Quote:

I cannot use sudo to do hard limit change like so:
$ sudo ulimit -H -n

which gives error.

And when I user su (root) like so:
$ su
<sign it here>
# set ulimit for -n (open files) to 8192:
$ ulimit -H -n 8192

It works, but once I exit su, those changes inside su were no longer valid outside of su.
So it seems su takes me into a new shell!

So how do I change hard limit without changing
/etc/security/limits.conf AND REBOOT in the present shell?
Every command that is not built-in to the shell is a new process. su goes to a new process, requires authentication and execs the shell - thus a different process, and a different shell.

Hard limits are only changed downward - that is what makes them hard limits. You can close the shell and start another... I believe that will restore the previous limits as they are inherited from the parent process.
 
2 members found this post helpful.
Old 05-09-2016, 12:59 PM   #3
fanoflq
Member
 
Registered: Nov 2015
Posts: 397

Original Poster
Rep: Reputation: Disabled
Thank you.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Cannot set ulimit -l, says ulimit: max locked memory: cannot modify limit Xiano Slackware 1 07-24-2014 02:58 AM
Increasing POSIX message queue limit using - ulimit -q option newbee8 Linux - Newbie 0 02-10-2014 01:44 PM
ulimit: open files: cannot modify limit: Operation not permitted Winanjaya Linux - Server 3 02-20-2012 12:43 AM
How can I change the limit of 'Open Files' in ulimit? thomas2004ch Linux - Newbie 10 11-17-2009 05:21 AM
ulimit -c does not limit the core file size after a particular point meetolnx Linux - Newbie 2 10-04-2007 12:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration