mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] rlim in proc/<pid>/status
@ 2008-01-15 10:06 Clifford Wolf
  2008-01-15 10:47 ` KOSAKI Motohiro
  2008-01-15 20:36 ` [PATCH] " serge
  0 siblings, 2 replies; 7+ messages in thread
From: Clifford Wolf @ 2008-01-15 10:06 UTC (permalink / raw)
  To: lkml

Hi,

because I needed it already twice in two different projects this week: the
following patch adds rlim (ulimits) output to /proc/<pid>/status.

Please let me know if there is another (already existing) way of accessing
this information easy (i.e. connecting with gdb to the process in question
and 'injecting' a getrlimit() call does not count.. ;-).

yours,
 - clifford

Signed-off-by: Clifford Wolf <clifford@clifford.at>

--- linux/fs/proc/array.c	(revision 757)
+++ linux/fs/proc/array.c	(working copy)
@@ -239,6 +239,55 @@
 	}
 }
 
+static char *rlim_names[RLIM_NLIMITS] = {
+	[RLIMIT_CPU]        = "CPU",
+	[RLIMIT_FSIZE]      = "FSize",
+	[RLIMIT_DATA]       = "Data",
+	[RLIMIT_STACK]      = "Stack",
+	[RLIMIT_CORE]       = "Core",
+	[RLIMIT_RSS]        = "RSS",
+	[RLIMIT_NPROC]      = "NProc",
+	[RLIMIT_NOFILE]     = "NoFile",
+	[RLIMIT_MEMLOCK]    = "MemLock",
+	[RLIMIT_AS]         = "AddrSpace",
+	[RLIMIT_LOCKS]      = "Locks",
+	[RLIMIT_SIGPENDING] = "SigPending",
+	[RLIMIT_MSGQUEUE]   = "MsgQueue",
+	[RLIMIT_NICE]       = "Nice",
+	[RLIMIT_RTPRIO]     = "RTPrio"
+};
+
+static inline char *task_rlim(struct task_struct *p, char *buffer)
+{
+	unsigned long flags;
+	struct rlimit rlim[RLIM_NLIMITS];
+	int i;
+	
+	rcu_read_lock();
+	if (lock_task_sighand(p, &flags)) {
+		for (i=0; i<RLIM_NLIMITS; i++)
+			rlim[i] = p->signal->rlim[i];
+	}
+	rcu_read_unlock();
+
+	for (i=0; i<RLIM_NLIMITS; i++) {
+		if (rlim_names[i])
+			buffer += sprintf(buffer, "Rlim%s:\t", rlim_names[i]);
+		else
+			buffer += sprintf(buffer, "Rlim%d:\t", i);
+		if (rlim[i].rlim_cur != ~0)
+			buffer += sprintf(buffer, "%lu\t", rlim[i].rlim_cur);
+		else
+			buffer += sprintf(buffer, "-\t");
+		if (rlim[i].rlim_max != ~0)
+			buffer += sprintf(buffer, "%lu\n", rlim[i].rlim_max);
+		else
+			buffer += sprintf(buffer, "-\n");
+	}
+
+	return buffer;
+}
+
 static inline char *task_sig(struct task_struct *p, char *buffer)
 {
 	unsigned long flags;
@@ -310,6 +359,7 @@
 		buffer = task_mem(mm, buffer);
 		mmput(mm);
 	}
+	buffer = task_rlim(task, buffer);
 	buffer = task_sig(task, buffer);
 	buffer = task_cap(task, buffer);
 	buffer = cpuset_task_status_allowed(task, buffer);

-- 
[..] If it still doesn't work, re-write it in assembler. This won't fix the
bug, but it will make sure no one else finds it and makes you look bad.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-01-16 10:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-15 10:06 [PATCH] rlim in proc/<pid>/status Clifford Wolf
2008-01-15 10:47 ` KOSAKI Motohiro
2008-01-15 12:15   ` Clifford Wolf
2008-01-15 20:36 ` [PATCH] " serge
2008-01-16  7:03   ` [PATCH] rlim in proc/<pid>/status (2nd rev.) Clifford Wolf
2008-01-16  7:33     ` KOSAKI Motohiro
2008-01-16 10:04       ` Clifford Wolf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®