you limit

Posted: June 7, 2007 in linux

it is true that you learn something new each day. and just recently, i just found out about this handy Linux tool for setting limits – ulimit.

below is a short description and command options for ulimit.

ulimit [-SHacdflmnpstuv [limit]]

Provides control over the resources available to the shell and to processes started by it, on systems that allow such control. The -H and -S options specify that the hard or soft limit is set for the given resource. A hard limit cannot be increased once it is set; a soft limit may be increased up to the value of the hard limit. If neither -H nor -S is specified, both the soft and hard limits are set. The value of limit can be a number in the unit specified for the resource or one of the special values hard, soft, or unlimited, which stand for the current hard limit, the current soft limit, and no limit, respectively. If limit is omitted, the current value of the soft limit of the resource is printed, unless the -H option is given. When more than one resource is specified, the limit name and unit are printed before the value. Other options are interpreted as follows:

-a All current limits are reported
-c The maximum size of core files created
-d The maximum size of a process’s data segment
-f The maximum size of files created by the shell
-l The maximum size that may be locked into memory
-m The maximum resident set size
-n The maximum number of open file descriptors (most systems do not allow this value to be set)
-p The pipe size in 512-byte blocks (this may not be set)
-s The maximum stack size
-t The maximum amount of cpu time in seconds
-u The maximum number of processes available to a single user
-v The maximum amount of virtual memory available to the shell

If limit is given, it is the new value of the specified resource. Otherwise, the current value of the soft limit for the specified resource is printed, unless the `-H’ option is supplied.

When setting new limits, if neither `-H’ nor `-S’ is supplied, both the hard and soft limits are set.

Values are in 1024-byte increments, except for `-t’, which is in seconds, `-p’, which is in units of 512-byte blocks, and `-n’ and `-u’, which are unscaled values.

The return status is zero unless an invalid option is supplied, a non-numeric argument other than unlimited is supplied as a limit, or an error occurs while setting a new limit.

`ulimit‘ is a BASH builtin command.

there is also another way for defining the limits on your system. you can do this by editing the file limits.conf, which is usually located in this directory /etc/security/.

# /etc/security/limits.conf
#
#Each line describes a limit for a user in the form:
#
#
#Where:
# can be:
# – an user name
# – a group name, with @group syntax
# – the wildcard *, for default entry
#
# can have the two values:
# – “soft” for enforcing the soft limits
# – “hard” for enforcing hard limits
#
# can be one of the following:
# – core – limits the core file size (KB)
# – data – max data size (KB)
# – fsize – maximum filesize (KB)
# – memlock – max locked-in-memory address space (KB)
# – nofile – max number of open files
# – rss – max resident set size (KB)
# – stack – max stack size (KB)
# – cpu – max CPU time (MIN)
# – nproc – max number of processes
# – as – address space limit
# – maxlogins – max number of logins for this user
# – priority – the priority to run user process with

#* soft core 0
#* hard rss 10000
#@student hard nproc 20
#@faculty soft nproc 20
#@faculty hard nproc 50
#ftp hard nproc 0
#@student – maxlogins 4

# End of file

Below are some examples on limiting how many processes a user may run, the maxium size of a file, and the number of open files.

Add the following lines to the limits.conf to restrict a user to the specified number or processes:

* soft nproc 100
* hard nproc 150

In order to restrict a user from having a file over 40MB, add this to limits.conf:

* hard 40000

If you want to limit the number of open files, edit limits.conf and add the following:

* soft nofile 4000
* hard nofile 4000

You can change 4000 to another number of your choosing.

The first argument from the lines above, which is an astertisk (*), means that it should be applied to any user. root however is not limited to what is in limits.conf. in fact it can’t be limited at all. and this would also apply to users with root privileges or those with a UID of zero (0).

Advertisements
Comments
  1. name says:

    Ever notice how fast Windows runs? Neither did I.

  2. <a href="http://phentermine.whdot.com/index14.html">disadvantages of phentermine</a> says:

    Thanks to author.

  3. <a href="http://m1.aol.com/BrettHead14/411.html">massachusetts dram shop insurance requirements</a> says:

    Please write anything else!

  4. <a href="http://free.7host07.com/nmcfgy/505.html">amalfi tours</a> says:

    Thanks to author.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s