ulimit Command

The ulimit command is a built-in shell command, which displays the current file size limit.  The default value for the Maximum file size, set inside the kernel is 1500 blocks.  

The Following syntax displays the current limit as

#ulimit -a
core file size (blocks, -c) unlimited
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 10
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 29995

virtual memory (kbytes, -v) unlimited

If the limit is not set, it reports as unlimited.

The system administrator and the individual user change this value to set the file size at the system level and at the user level, respectively.  The following is the syntax of the ulimit command

ulmit <value>

The file size can be limited at the system level or the user level, let see few setting at system level at different OS.


edit /etc/system with following entries

set rlim_fd_max = 4096 # Hard limit on file descriptors for a single proc
##(Without this above condition, the default value for nofiles is half of the rlim_fd_cur)
set rlim_fd_cur = 1024 # Soft limit on file descriptors for a single proc


you can configure ulimits for each user here

stack = 393216
stack_hard = 393216


you can configure ulimits for each user here

username hard nofile 4096
username soft nofile 63536

Hard and soft limits of 4096 for 'nofile' (all users) 
* soft nofile 4096 
* hard nofile 4096 

The "soft limit" in the first line defines the number of file handles or open files that the 

user will have after login.

If the Oracle gets error messages about running out of file handles, then the user can increase 

the number of file handles like in this example up to 63536 ("hard limit") by executing the 

following command:

ulimit -n 63536

You can set the "soft" and "hard" limits higher if necessary.

Do not set the "hard" limit for nofile for the user equal to /proc/sys/fs/file-max. If you do that and the user uses up all the file handles, then the entire system will run out of file handles.

 This could mean that you won't be able to initiate new logins any more since the system won't be able to open any PAM modules that are required for the login process. That's why I set the hard limit to 63536 and not 65536.

Note: you have to reboot the server after these changes

Help command on Linux

$ help -m ulimit

    ulimit - Modify shell resource limits.

    ulimit [-SHacdefilmnpqrstuvx] [limit]

    Modify shell resource limits.

    Provides control over the resources available to the shell and processes
    it creates, on systems that allow such control.

      -S        use the `soft' resource limit
      -H        use the `hard' resource limit
      -a        all current limits are reported
      -b        the socket buffer size
      -c        the maximum size of core files created
      -d        the maximum size of a process's data segment
      -e        the maximum scheduling priority (`nice')
      -f        the maximum size of files written by the shell and its children
      -i        the maximum number of pending signals
      -l        the maximum size a process may lock into memory
      -m        the maximum resident set size
      -n        the maximum number of open file descriptors
      -p        the pipe buffer size
      -q        the maximum number of bytes in POSIX message queues
      -r        the maximum real-time scheduling priority
      -s        the maximum stack size
      -t        the maximum amount of cpu time in seconds
      -u        the maximum number of user processes
      -v        the size of virtual memory
      -x        the maximum number of file locks

    If LIMIT is given, it is the new value of the specified resource; the
    special LIMIT values `soft', `hard', and `unlimited' stand for the
    current soft limit, the current hard limit, and no limit, respectively.
    Otherwise, the current value of the specified resource is printed.  If
    no option is given, then -f is assumed.

    Values are in 1024-byte increments, except for -t, which is in seconds,
    -p, which is in increments of 512 bytes, and -u, which is an unscaled
    number of processes.

    Exit Status:
    Returns success unless an invalid option is supplied or an error occurs.


    GNU bash, version 4.0.16(1)-release (i386-redhat-linux-gnu)
    Copyright (C) 2009 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later 

To Set Soft and Hard limits.

The command ulimit -Xa will display all current settings that are set for the current login session, where X represents the hard (H) or soft (S) limits to be displayed. By default, if no value is supplied for X, soft limits will be displayed.

Soft limits are the current setting for a particular limit. They can be increased only to the current hard limit setting.
Hard limits are the maximum limit that can be configured. Any changes to these require root access.
Temporary Settings (for current session)

ulimit -[H|S]limit_name limit_value

Temporary settings are set via the command line using the ulimit command. These settings are only temporary for the current session and will be lost once the session is over or the terminal window is closed.

This syntax can be used within shell scripts. Any processes spawned from these shell scripts will also have the temporary settings for the lifetime they are running.

By default, the soft limit will be changed (as changing the hard limit needs root access). Use -H (for hard limits) or -S (for soft limits) to change specific hard or soft limits.

No comments:

Post a Comment