Re: [PATCH] Introduce ActivePid: in /proc/self/status (v2, wasVpid:)

From: Greg Kurz
Date: Thu Jun 16 2011 - 11:33:50 EST


On Thu, 2011-06-16 at 08:07 -0700, Eric W. Biederman wrote:
> > Finally, we thought that the 'ActivePid' information was interesting
> > enough to be exposed in /proc and was solving the case we're facing
> > rather easily with some framework (cgroups) in user space.
>
> The pid number by which a process knows itself doesn't seem
> unreasonable. I'm not totally
>
> After having a second look at the code in proc we already have
> a reference to the struct pid we want to print. So simply
> printing
> pid->numbers[pid->level].nr
> seems reasonable, and race free.
>
> Alternatively that could be written.
> pid_nr_ns(pid, ns_of_pid(pid));
>
> Eric

So we end up with the following, since pid is valid:

diff --git a/fs/proc/array.c b/fs/proc/array.c
index 5e4f776..b7316cc 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -183,12 +183,14 @@ static inline void task_state(struct seq_file *m,
struct pid_namespace *ns,
"Pid:\t%d\n"
"PPid:\t%d\n"
"TracerPid:\t%d\n"
+ "ActivePid:\t%d\n"
"Uid:\t%d\t%d\t%d\t%d\n"
"Gid:\t%d\t%d\t%d\t%d\n",
get_task_state(p),
task_tgid_nr_ns(p, ns),
pid_nr_ns(pid, ns),
ppid, tpid,
+ pid_nr_ns(pid, ns_of_pid(pid)),
cred->uid, cred->euid, cred->suid, cred->fsuid,
cred->gid, cred->egid, cred->sgid, cred->fsgid);

--
Gregory Kurz gkurz@xxxxxxxxxx
Software Engineer @ IBM/Meiosys http://www.ibm.com
Tel +33 (0)534 638 479 Fax +33 (0)561 400 420

"Anarchy is about taking complete responsibility for yourself."
Alan Moore.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/