limits is a FreeBSD’s base system utility for displaying and setting system resources limits. To some extent it is equivalent to the limit and ulimit commands. It can set limits for filesize, coredumpsize, maxproc, memoryuse and other parameters. Convenience modifiers like k, m or g for kilobytes, megabytes and gigabytes or s, m, h for seconds, minutes and hours can be used in all cases.
limits can be used to achieve three different goals:
- Set resource limits.
For example:$ limits -t 1s ls -R /launches the
ls -Rcommand with a cputime limit of 1 second. In general, this is the output that will be generated:... ... ... Killed: 9If we want to know what happened, we can have a look at the system message buffer:
$ dmesg pid 1651 (ls), uid 1001, was killed: exceeded maximum CPU limit - Show resource limits
If we just want some information about resource limits, we can invoke the command this way:$ limits Resource limits (current): cputime infinity secs filesize infinity kB datasize 33554432 kB stacksize 524288 kB coredumpsize infinity kB memoryuse infinity kB memorylocked infinity kB maxprocesses 5547 openfiles 11095 sbsize infinity bytes vmemoryuse infinity kB pseudo-terminals infinity swapuse infinity kBOr if we are interested in one particular resource:
$ limits -c Resource limits (current): coredumpsize infinity kB - Report resource limits in a way suitable for feeding a shell.
This is pretty smart. Sometimes you want to set some limits on the invoking shell but simply callinglimitswill set the resource limit for the forked shell. If you don’t know what I am talking about, have a look at the fork-exec model for spawning processes in UNIX systems.limitstransforms the resource limit command to the appropriate command for the invoking shell using eitherulimitorlimitdepending on the shell. Thelimitcommand knows the following shells: sh, csh, bash, tcsh, ksh, pdksh and rc). Invokinglimitswith the-eflag results in the following output:$ limits -e -t 10s ulimit -t 10;It makes sense, since I am using bash. We can use this output together with the
evalbuilt-in command to apply the limit to the current shell:$ eval `limits -e -t 10s` $ limits -t Resource limits (current): cputime 10 secs
That’s all for today.
Enjoy!
Add your comment below, or trackback from your own site.
Subscribe to these comments.
Be nice. Keep it clean. Stay on topic. No spam.
You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>