linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] [PATCH procfs] Add process age
@ 2010-07-23 17:47 Davidlohr Bueso
  2010-07-23 18:35 ` Alexey Dobriyan
  0 siblings, 1 reply; 10+ messages in thread
From: Davidlohr Bueso @ 2010-07-23 17:47 UTC (permalink / raw)
  To: torvalds; +Cc: linux-kernel, linux-fsdevel

Hi,

This patch exports a process's age, in seconds, adding a /proc/#/age file.

Thanks,
Davidlohr

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
---
 fs/proc/base.c |   19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index acb7ef8..a5a4832 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -38,13 +38,16 @@
  *  ChangeLog:
  *  10-Mar-2005
  *  10LE Instituto Nokia de Tecnologia - INdT:
- *  A better way to walks through the page table as suggested by Hugh Dickins.
+ *  A better way to walk through the page table as suggested by Hugh Dickins.
  *
  *  Simo Piiroinen <simo.piiroinen@nokia.com>:
  *  Smaps information related to shared, private, clean and dirty pages.
  *
  *  Paul Mundt <paul.mundt@nokia.com>:
  *  Overall revision about smaps.
+ *
+ *  2010 - Davidlohr Bueso <dave@gnu.org>:
+ *  Added process age (/proc/#/age), in seconds.
  */
 
 #include <asm/uaccess.h>
@@ -2558,6 +2561,18 @@ static int proc_pid_personality(struct seq_file *m, struct pid_namespace *ns,
 	return 0;
 }
 
+static int proc_pid_age(struct seq_file *m, struct pid_namespace *ns,
+			struct pid *pid, struct task_struct *task)
+{
+	struct timespec uptime;
+
+	do_posix_clock_monotonic_gettime(&uptime);
+	monotonic_to_bootbased(&uptime);
+	seq_printf(m, "%lu\n", uptime.tv_sec - task->real_start_time.tv_sec);
+
+	return 0;
+}
+
 /*
  * Thread groups
  */
@@ -2575,6 +2590,7 @@ static const struct pid_entry tgid_base_stuff[] = {
 	INF("auxv",       S_IRUSR, proc_pid_auxv),
 	ONE("status",     S_IRUGO, proc_pid_status),
 	ONE("personality", S_IRUSR, proc_pid_personality),
+	ONE("age",        S_IRUSR, proc_pid_age),
 	INF("limits",	  S_IRUSR, proc_pid_limits),
 #ifdef CONFIG_SCHED_DEBUG
 	REG("sched",      S_IRUGO|S_IWUSR, proc_pid_sched_operations),
@@ -2910,6 +2926,7 @@ static const struct pid_entry tid_base_stuff[] = {
 	INF("auxv",      S_IRUSR, proc_pid_auxv),
 	ONE("status",    S_IRUGO, proc_pid_status),
 	ONE("personality", S_IRUSR, proc_pid_personality),
+	ONE("age",        S_IRUSR, proc_pid_age),
 	INF("limits",	 S_IRUSR, proc_pid_limits),
 #ifdef CONFIG_SCHED_DEBUG
 	REG("sched",     S_IRUGO|S_IWUSR, proc_pid_sched_operations),
-- 
1.7.0.4


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

* Re: [RFC] [PATCH procfs] Add process age
  2010-07-23 17:47 [RFC] [PATCH procfs] Add process age Davidlohr Bueso
@ 2010-07-23 18:35 ` Alexey Dobriyan
  2010-07-23 18:47   ` Davidlohr Bueso
  0 siblings, 1 reply; 10+ messages in thread
From: Alexey Dobriyan @ 2010-07-23 18:35 UTC (permalink / raw)
  To: Davidlohr Bueso; +Cc: torvalds, linux-kernel, linux-fsdevel

On Fri, Jul 23, 2010 at 01:47:51PM -0400, Davidlohr Bueso wrote:
> This patch exports a process's age, in seconds, adding a /proc/#/age file.

What for?

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

* Re: [RFC] [PATCH procfs] Add process age
  2010-07-23 18:35 ` Alexey Dobriyan
@ 2010-07-23 18:47   ` Davidlohr Bueso
  2010-07-23 23:16     ` Sergey V.
  2010-07-26  7:47     ` Andi Kleen
  0 siblings, 2 replies; 10+ messages in thread
From: Davidlohr Bueso @ 2010-07-23 18:47 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: torvalds, linux-kernel, linux-fsdevel

On Fri, 2010-07-23 at 21:35 +0300, Alexey Dobriyan wrote:
> On Fri, Jul 23, 2010 at 01:47:51PM -0400, Davidlohr Bueso wrote:
> > This patch exports a process's age, in seconds, adding a /proc/#/age file.
> 
> What for?

I have not found any straight way to get the run time of a processes,
without having to interpret the start_time entry in /proc/#/stat and
manually subtract the uptime from it.

This small file simply aids the users to obtain the information easier
and quicker. Another alternative would be to add an entry
in /proc/#/status.

Davidlohr

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

* Re: [RFC] [PATCH procfs] Add process age
  2010-07-23 18:47   ` Davidlohr Bueso
@ 2010-07-23 23:16     ` Sergey V.
  2010-07-26  7:47     ` Andi Kleen
  1 sibling, 0 replies; 10+ messages in thread
From: Sergey V. @ 2010-07-23 23:16 UTC (permalink / raw)
  To: dave.bueso; +Cc: Alexey Dobriyan, torvalds, linux-kernel, linux-fsdevel

On Friday 23 of July 2010 22:47:10 Davidlohr Bueso wrote:
> On Fri, 2010-07-23 at 21:35 +0300, Alexey Dobriyan wrote:
> > On Fri, Jul 23, 2010 at 01:47:51PM -0400, Davidlohr Bueso wrote:
> > > This patch exports a process's age, in seconds, adding a /proc/#/age 
file.
> > 
> > What for?
> 
> I have not found any straight way to get the run time of a processes,
> without having to interpret the start_time entry in /proc/#/stat and
> manually subtract the uptime from it.

Agree. I thing this feature can be useful in some cases.

I have not found better than run something like this:

echo `cat /proc/uptime | awk '{print $1}'` - \
     `cat /proc/$PID/stat | awk '{print $22}'`/100 | bc

> This small file simply aids the users to obtain the information easier
> and quicker. Another alternative would be to add an entry
> in /proc/#/status.
> 
> Davidlohr

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

* Re: [RFC] [PATCH procfs] Add process age
  2010-07-23 18:47   ` Davidlohr Bueso
  2010-07-23 23:16     ` Sergey V.
@ 2010-07-26  7:47     ` Andi Kleen
  2010-07-26 13:57       ` Davidlohr Bueso
  1 sibling, 1 reply; 10+ messages in thread
From: Andi Kleen @ 2010-07-26  7:47 UTC (permalink / raw)
  To: dave.bueso; +Cc: Alexey Dobriyan, torvalds, linux-kernel, linux-fsdevel

Davidlohr Bueso <dave.bueso@gmail.com> writes:

> On Fri, 2010-07-23 at 21:35 +0300, Alexey Dobriyan wrote:
>> On Fri, Jul 23, 2010 at 01:47:51PM -0400, Davidlohr Bueso wrote:
>> > This patch exports a process's age, in seconds, adding a /proc/#/age file.
>> 
>> What for?
>
> I have not found any straight way to get the run time of a processes,
> without having to interpret the start_time entry in /proc/#/stat and
> manually subtract the uptime from it.

That sounds like something an user space program should simply do.
Perhaps you can add it as a new optional "-o" field in "ps" ?

-Andi

-- 
ak@linux.intel.com -- Speaking for myself only.

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

* Re: [RFC] [PATCH procfs] Add process age
  2010-07-26  7:47     ` Andi Kleen
@ 2010-07-26 13:57       ` Davidlohr Bueso
  2010-07-26 14:48         ` Andi Kleen
  0 siblings, 1 reply; 10+ messages in thread
From: Davidlohr Bueso @ 2010-07-26 13:57 UTC (permalink / raw)
  To: Andi Kleen; +Cc: Alexey Dobriyan, torvalds, linux-kernel, linux-fsdevel

On Mon, 2010-07-26 at 09:47 +0200, Andi Kleen wrote:
> Davidlohr Bueso <dave.bueso@gmail.com> writes:
> 
> > On Fri, 2010-07-23 at 21:35 +0300, Alexey Dobriyan wrote:
> >> On Fri, Jul 23, 2010 at 01:47:51PM -0400, Davidlohr Bueso wrote:
> >> > This patch exports a process's age, in seconds, adding a /proc/#/age file.
> >> 
> >> What for?
> >
> > I have not found any straight way to get the run time of a processes,
> > without having to interpret the start_time entry in /proc/#/stat and
> > manually subtract the uptime from it.
> 
> That sounds like something an user space program should simply do.
> Perhaps you can add it as a new optional "-o" field in "ps" ?
> 
True, but there are also many other no-so-useful files under /proc that
can also be replaced by userspace apps.

Davidlohr


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

* Re: [RFC] [PATCH procfs] Add process age
  2010-07-26 13:57       ` Davidlohr Bueso
@ 2010-07-26 14:48         ` Andi Kleen
  2010-07-26 15:10           ` Davidlohr Bueso
  0 siblings, 1 reply; 10+ messages in thread
From: Andi Kleen @ 2010-07-26 14:48 UTC (permalink / raw)
  To: Davidlohr Bueso
  Cc: Andi Kleen, Alexey Dobriyan, torvalds, linux-kernel,
	linux-fsdevel

> True, but there are also many other no-so-useful files under /proc that
> can also be replaced by userspace apps.

Example? 

-andi
-- 
ak@linux.intel.com -- Speaking for myself only.

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

* Re: [RFC] [PATCH procfs] Add process age
  2010-07-26 14:48         ` Andi Kleen
@ 2010-07-26 15:10           ` Davidlohr Bueso
  2010-07-28  6:56             ` Américo Wang
  0 siblings, 1 reply; 10+ messages in thread
From: Davidlohr Bueso @ 2010-07-26 15:10 UTC (permalink / raw)
  To: Andi Kleen; +Cc: Alexey Dobriyan, torvalds, linux-kernel, linux-fsdevel

On Mon, 2010-07-26 at 16:48 +0200, Andi Kleen wrote:
> > True, but there are also many other no-so-useful files under /proc that
> > can also be replaced by userspace apps.
> 
> Example? 

Off the top of my head:

/proc/cmdline
Several entries in /proc/#/status, like Name, PPid, Gid, Uid, etc.

I am not criticizing this, I think some repetitive data is good for
users. Just showing that other features can also be obtained from
userspace.

Davidlohr

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

* Re: [RFC] [PATCH procfs] Add process age
  2010-07-26 15:10           ` Davidlohr Bueso
@ 2010-07-28  6:56             ` Américo Wang
  2010-07-30 14:58               ` Davidlohr Bueso
  0 siblings, 1 reply; 10+ messages in thread
From: Américo Wang @ 2010-07-28  6:56 UTC (permalink / raw)
  To: Davidlohr Bueso
  Cc: Andi Kleen, Alexey Dobriyan, torvalds, linux-kernel,
	linux-fsdevel

On Mon, Jul 26, 2010 at 11:10:29AM -0400, Davidlohr Bueso wrote:
>On Mon, 2010-07-26 at 16:48 +0200, Andi Kleen wrote:
>> > True, but there are also many other no-so-useful files under /proc that
>> > can also be replaced by userspace apps.
>> 
>> Example? 
>
>Off the top of my head:
>
>/proc/cmdline

Are you kidding?

/proc/cmdlines contains lots of info, it is not only used by the kernel,
but also used by initramfs (this depends on your distribution).


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

* Re: [RFC] [PATCH procfs] Add process age
  2010-07-28  6:56             ` Américo Wang
@ 2010-07-30 14:58               ` Davidlohr Bueso
  0 siblings, 0 replies; 10+ messages in thread
From: Davidlohr Bueso @ 2010-07-30 14:58 UTC (permalink / raw)
  To: Américo Wang
  Cc: Andi Kleen, Alexey Dobriyan, torvalds, linux-kernel,
	linux-fsdevel

On Wed, 2010-07-28 at 14:56 +0800, Américo Wang wrote:
> On Mon, Jul 26, 2010 at 11:10:29AM -0400, Davidlohr Bueso wrote:
> >On Mon, 2010-07-26 at 16:48 +0200, Andi Kleen wrote:
> >> > True, but there are also many other no-so-useful files under /proc that
> >> > can also be replaced by userspace apps.
> >> 
> >> Example? 
> >
> >Off the top of my head:
> >
> >/proc/cmdline
> 
> Are you kidding?
> 
> /proc/cmdlines contains lots of info, it is not only used by the kernel,
> but also used by initramfs (this depends on your distribution).
> 
Silly me, I meant /proc/#/cmdline, in the sense that you can get the
command name from the PID in userland.

Davidlohr


--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2010-07-30 14:59 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-23 17:47 [RFC] [PATCH procfs] Add process age Davidlohr Bueso
2010-07-23 18:35 ` Alexey Dobriyan
2010-07-23 18:47   ` Davidlohr Bueso
2010-07-23 23:16     ` Sergey V.
2010-07-26  7:47     ` Andi Kleen
2010-07-26 13:57       ` Davidlohr Bueso
2010-07-26 14:48         ` Andi Kleen
2010-07-26 15:10           ` Davidlohr Bueso
2010-07-28  6:56             ` Américo Wang
2010-07-30 14:58               ` Davidlohr Bueso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).