Previous | Table of Contents | Next |
DESCRIPTION
The internal ulimit command sets an automatic resource limit. The limit applies to the current process and all processes it spawns. The limit is set as a maximum number of resources a process can have. The ulimit command allows you to:
C Shell |
---|
The csh version of ulimit, named limit, allows the same type of resource control as the ksh's ulimit.These limits can be removed by using the unlimit command. |
COMMAND FORMAT
Following is the general format of the ulimit command.
ulimit [ -[HS]a|cdfnstv ] ulimit [ -[HS]c|d|f|n|s|t|v ] limit ulimit [ limit ]
C Shell | |
---|---|
limit [ -h ] [ resource [ limit ] ] unlimit [ -h ] [ resource [ limit ] ] |
|
Options
The following options may be used to control how ulimit functions. If the limit argument is specified, then the options perform as described; otherwise, they display the current limits.
-H | Set or display hard limits. A user cannot increase hard limits. |
-S | Set or display soft limits. A user can increase or decrease soft limits. The maximum soft limit must be less than the hard limit value. |
-a | Display all limits. |
-c | Sets the size of the core file to limit kilobytes. |
-d | Sets the size of the data area to limit kilobytes. |
-f | Set the size limit for files written by the current shell and its child processes to n blocks. The largest file you can create is n kilobytes. |
-s | Sets the size of the stack space to limit kilobytes. |
-t | Sets each process to a specified cpu time limit of limit seconds. |
-v | Sets the size of virtural memory to limit kilobytes. |
If no option is given and limit is provided, the -f option is assumed. | |
If no option is given and limit is not provided, then the current ulimit for -f (file size) is displayed. |
C Shell | |
---|---|
-h | Sets the hard limits instead of the soft limits. Only a priviledged user (root) can set hard limits. |
Arguments
Only one argument may be passed to the ulimit command.
limit | Set the file size limit to n blocks for all files created by the current shell and its child processes. |
C Shell | |
---|---|
Where resource is one of the following. | |
cputime | Same as ksh -t |
filesize | Same as ksh -f |
datasize | Same as ksh -d |
stacksize | Same as ksh -s |
coredumpsize | Same as ksh -c |
The limit can be scaled in the csh. The scaling factors are: | |
limith | Hours (cpu time only) |
limitk | Kilobytes |
limitm | Megabytes |
mm:ss | Minutes and seconds (cpu time only) |
If no arguments are provided the current limits are displayed. |
APPLICATIONS
The ulimit command is used to control resource limits. It is beneficial in a testing environment, where you may have a program that enters an endless loop while writing to a file. By having ulimit set you can only write n number of blocks to disk before the system kills (terminates) your program. It may also be used in application programs to control the size of files a user may generate while using the application.
Usually it is used to reduce the maximum file size for users. The super-user can use ulimit to increase the upper limit of file sizes if necessary.
TYPICAL OPERATION
In this activity you use the ulimit command to set your maximum file size to one. Begin at the shell prompt.
C Shell | |
---|---|
If you are using the csh, replace the ulimit command with limit f in the following exercises. | |
Bourne and Korn Shell Only (sh and ksh) | |
Since the ulimit command resets the maximum size file you can create, you should enter a subshell. This will keep ulimit from changing your login shells file size limit. | |
To do this type ksh and press Return. | |
cj> ls -l /etc/passwd passwd -rw-r--r-- 1 root root 8197 Jan 1 17:23 /etc/passwd -rw-r--r-- 1 mylogin ts 512 Jan 1 17:23 passwd
Bourne and Korn Shell Only (sh and ksh) | |
---|---|
Return to your login shell by typing exit and pressing Return or by pressing Ctrl-D. | |
Previous | Table of Contents | Next |