aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Horman <nhorman@tuxdriver.com>2007-10-19 02:40:37 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-19 14:53:42 -0400
commitd85f50d5e1aa99ab082035f94265847521819e58 (patch)
treee0c96611352d760dfa54199e706fc76ce8975871
parent14ed9d23aa9acd79210a92ac561a728b42a8e281 (diff)
proc: export a processes resource limits via /proc/pid
Currently, there exists no method for a process to query the resource limits of another process. They can be inferred via some mechanisms but they cannot be explicitly determined. Given that this information can be usefull to know during the debugging of an application, I've written this patch which exports all of a processes limits via /proc/<pid>/limits. Signed-off-by: Neil Horman <nhorman@tuxdriver.com> Cc: Oleg Nesterov <oleg@tv-sign.ru> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--fs/proc/base.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 991482811f1e..54c2e5621afb 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -63,6 +63,7 @@
63#include <linux/mm.h> 63#include <linux/mm.h>
64#include <linux/rcupdate.h> 64#include <linux/rcupdate.h>
65#include <linux/kallsyms.h> 65#include <linux/kallsyms.h>
66#include <linux/resource.h>
66#include <linux/module.h> 67#include <linux/module.h>
67#include <linux/mount.h> 68#include <linux/mount.h>
68#include <linux/security.h> 69#include <linux/security.h>
@@ -303,6 +304,78 @@ static int proc_oom_score(struct task_struct *task, char *buffer)
303 return sprintf(buffer, "%lu\n", points); 304 return sprintf(buffer, "%lu\n", points);
304} 305}
305 306
307struct limit_names {
308 char *name;
309 char *unit;
310};
311
312static const struct limit_names lnames[RLIM_NLIMITS] = {
313 [RLIMIT_CPU] = {"Max cpu time", "ms"},
314 [RLIMIT_FSIZE] = {"Max file size", "bytes"},
315 [RLIMIT_DATA] = {"Max data size", "bytes"},
316 [RLIMIT_STACK] = {"Max stack size", "bytes"},
317 [RLIMIT_CORE] = {"Max core file size", "bytes"},
318 [RLIMIT_RSS] = {"Max resident set", "bytes"},
319 [RLIMIT_NPROC] = {"Max processes", "processes"},
320 [RLIMIT_NOFILE] = {"Max open files", "files"},
321 [RLIMIT_MEMLOCK] = {"Max locked memory", "bytes"},
322 [RLIMIT_AS] = {"Max address space", "bytes"},
323 [RLIMIT_LOCKS] = {"Max file locks", "locks"},
324 [RLIMIT_SIGPENDING] = {"Max pending signals", "signals"},
325 [RLIMIT_MSGQUEUE] = {"Max msgqueue size", "bytes"},
326 [RLIMIT_NICE] = {"Max nice priority", NULL},
327 [RLIMIT_RTPRIO] = {"Max realtime priority", NULL},
328};
329
330/* Display limits for a process */
331static int proc_pid_limits(struct task_struct *task, char *buffer)
332{
333 unsigned int i;
334 int count = 0;
335 unsigned long flags;
336 char *bufptr = buffer;
337
338 struct rlimit rlim[RLIM_NLIMITS];
339
340 rcu_read_lock();
341 if (!lock_task_sighand(task,&flags)) {
342 rcu_read_unlock();
343 return 0;
344 }
345 memcpy(rlim, task->signal->rlim, sizeof(struct rlimit) * RLIM_NLIMITS);
346 unlock_task_sighand(task, &flags);
347 rcu_read_unlock();
348
349 /*
350 * print the file header
351 */
352 count += sprintf(&bufptr[count], "%-25s %-20s %-20s %-10s\n",
353 "Limit", "Soft Limit", "Hard Limit", "Units");
354
355 for (i = 0; i < RLIM_NLIMITS; i++) {
356 if (rlim[i].rlim_cur == RLIM_INFINITY)
357 count += sprintf(&bufptr[count], "%-25s %-20s ",
358 lnames[i].name, "unlimited");
359 else
360 count += sprintf(&bufptr[count], "%-25s %-20lu ",
361 lnames[i].name, rlim[i].rlim_cur);
362
363 if (rlim[i].rlim_max == RLIM_INFINITY)
364 count += sprintf(&bufptr[count], "%-20s ", "unlimited");
365 else
366 count += sprintf(&bufptr[count], "%-20lu ",
367 rlim[i].rlim_max);
368
369 if (lnames[i].unit)
370 count += sprintf(&bufptr[count], "%-10s\n",
371 lnames[i].unit);
372 else
373 count += sprintf(&bufptr[count], "\n");
374 }
375
376 return count;
377}
378
306/************************************************************************/ 379/************************************************************************/
307/* Here the fs part begins */ 380/* Here the fs part begins */
308/************************************************************************/ 381/************************************************************************/
@@ -2110,6 +2183,7 @@ static const struct pid_entry tgid_base_stuff[] = {
2110 REG("environ", S_IRUSR, environ), 2183 REG("environ", S_IRUSR, environ),
2111 INF("auxv", S_IRUSR, pid_auxv), 2184 INF("auxv", S_IRUSR, pid_auxv),
2112 INF("status", S_IRUGO, pid_status), 2185 INF("status", S_IRUGO, pid_status),
2186 INF("limits", S_IRUSR, pid_limits),
2113#ifdef CONFIG_SCHED_DEBUG 2187#ifdef CONFIG_SCHED_DEBUG
2114 REG("sched", S_IRUGO|S_IWUSR, pid_sched), 2188 REG("sched", S_IRUGO|S_IWUSR, pid_sched),
2115#endif 2189#endif
@@ -2435,6 +2509,7 @@ static const struct pid_entry tid_base_stuff[] = {
2435 REG("environ", S_IRUSR, environ), 2509 REG("environ", S_IRUSR, environ),
2436 INF("auxv", S_IRUSR, pid_auxv), 2510 INF("auxv", S_IRUSR, pid_auxv),
2437 INF("status", S_IRUGO, pid_status), 2511 INF("status", S_IRUGO, pid_status),
2512 INF("limits", S_IRUSR, pid_limits),
2438#ifdef CONFIG_SCHED_DEBUG 2513#ifdef CONFIG_SCHED_DEBUG
2439 REG("sched", S_IRUGO|S_IWUSR, pid_sched), 2514 REG("sched", S_IRUGO|S_IWUSR, pid_sched),
2440#endif 2515#endif