Monday, 30 May 2016

HARD AND SOFT LIMIT IN UNIX or LINUX

 

Normal user in linux or unix is restricted to create file descriptor after a certain value.  Normal user cannot create a fd more than the allowed limit.
This limit was set by the root user to the normal users. To know threshold of fd can be created, just  use the following command

ulimit –n

There are two types of limit
  • Hard limit
  • soft Limit

Hard Limit

Hard limit was set by the root user. Hard limit  says maximum number of fd that the user was allowed to create.
 Normal user can modify the hard limit but normal user can decrease the hard limit but normal user cannot increase it.

To know about the hard limit

ulimit –Hn

To set the hard limit
ulimit –Hn 100

This means that hard limit is set to 100.

Soft Limit

soft limit  says maximum number of fd that the user was allowed to create.

Then what is the difference between hard and soft limit?

If hard and soft limit both were same then limit to user is also same value. But If hard limit is higher and soft limit is low then soft limit is the limit value.

Then why we need a two types of limit?
Hard limit is used to restrict the Normal user to go beyond the allocated limit. Soft limit is used to set the limit according to their need. Say suppose Root user allocates limit as 100. then if you don’t want 100 to be set. Then you can change the soft limit to 50. So your limit is 50 now.
Normal user can  change the value of the soft limit (Not more than the hard limit). So the user has the control to set the limit according to their needs.

Soft limit is one which is equal or less than the hard limit. Soft limit cannot be greater than the hard limit.

To know about the soft  limit
ulimit –Sn

To set the hard limit
ulimit –Sn 50

This means that soft limit is set to 50.


The soft limit and hard limit you set during that session  is not permanent. It will be reseted to default value while starting a new session.