plimit for Linux

Problem

In Unix/Linux, ulimit(3) displays and sets user limits for the current process. In Solaris >= 8, there is another handy tool, plimit, that displays and sets per-process user limits on any running arbitrary process. This SystemTap does the display per-process user limits function of the plimit tool.

TODO: I welcome volunteers to help me finish the set per-process user limits bits.

Scripts

plimit.sh Updated 20 Jan 2008

Output

[eteo@kerndev ~]$ ./plimit.stp -g $$
9033:  -bash
 resource                    current    maximum
coredump(blocks)            0          unlimited
data(bytes)                 unlimited  unlimited
max nice                    0          0
file size(blocks)           unlimited  unlimited
pending signals             16366      16366
max locked memory(bytes)    32768      32768
max memory size(bytes)      unlimited  unlimited
open files                  1024       1024
POSIX message queues(bytes) 819200     819200
max rt priority             0          0
stack size(bytes)           10485760   unlimited
cpu time(seconds)           unlimited  unlimited
max user processes          16366      16366
virtual memory(bytes)       unlimited  unlimited
file locks                  unlimited  unlimited
[eteo@kerndev ~]$ ./plimit.stp -g `pgrep gnome-terminal`
3622:  -gnome-terminal
 resource                    current    maximum
coredump(blocks)            0          unlimited
data(bytes)                 unlimited  unlimited
max nice                    0          0
file size(blocks)           unlimited  unlimited
pending signals             16366      16366
max locked memory(bytes)    32768      32768
max memory size(bytes)      unlimited  unlimited
open files                  1024       1024
POSIX message queues(bytes) 819200     819200
max rt priority             0          0
stack size(bytes)           10485760   unlimited
cpu time(seconds)           unlimited  unlimited
max user processes          16366      16366
virtual memory(bytes)       unlimited  unlimited
file locks                  unlimited  unlimited

Patch for RHEL4

plimit.stp will need the following patch to compile on RHEL4. Instead of the patch, it is possible to put KERNEL_VERSION #if/#endif's into the embedded-C code to make it generic.

Without patch the following error occurs:

$ ./plimit.stp -g $$
# Pass 4: compilation failed.  Try again with more '-v' (verbose) options.

*** plimit.stp  2006-10-30 10:46:19.000000000 -0500
--- plimit.stp.new      2007-01-30 09:42:38.000000000 -0500
***************
*** 20,27 ****

        list_for_each_safe(_p, _n, &current->tasks) {
                p = list_entry(_p, struct task_struct, tasks);
!               cur = p->signal->rlim[THIS->rlim].rlim_cur;
!               max = p->signal->rlim[THIS->rlim].rlim_max;

                if (p->pid == (int)THIS->pid) {
                        if (cur == -1 && max == -1)
--- 20,27 ----

        list_for_each_safe(_p, _n, &current->tasks) {
                p = list_entry(_p, struct task_struct, tasks);
!               cur = p->rlim[THIS->rlim].rlim_cur;
!               max = p->rlim[THIS->rlim].rlim_max;

                if (p->pid == (int)THIS->pid) {
                        if (cur == -1 && max == -1)

Lessons

SystemTap gives you the flexibility to write kernel code with the -g guru mode, if necessary. You can start writing useful systems tools that are not available in Linux with SystemTap.


None: WSPlimit (last edited 2008-01-20 05:13:59 by EugeneTeo)