Add process age
Subsystems (2)
RFC PATCH 1/1 Add process age
Hi,
This patch exports a process's age, in seconds, adding a /proc/#/age file.
Thanks,
Davidlohr
--- fs/proc/base.c | 19 ++++++++++++++++++- 1 files changed, 18 insertions(+), 1 deletions(-)
fs/proc/base.c +18 -1
@@ -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 <[email protected]>: * Smaps information related to shared, private, clean and dirty pages. * * Paul Mundt <[email protected]>: * Overall revision about smaps. +* +* 2010 - Davidlohr Bueso <[email protected]>: +* 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),
Signature · 1 line
1.7.0.4
Quoted 1 line · Davidlohr Bueso
This patch exports a process's age, in seconds, adding a /proc/#/age file.
What for?
Quoted 4 lines · Alexey Dobriyan
Quoted 1 line · Davidlohr Bueso
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
Quoted 3 lines · On Friday 23 of July 2010 22:47:10 Davidlohr Bueso wrote:
Quoted 2 lines · Alexey Dobriyan
Quoted 1 line · Davidlohr Bueso
This patch exports a process's age, in seconds, adding a /proc/#/age
file.
Quoted 6 lines
Quoted 2 lines
What for?
I have not found any straight way to get the run time of a processes, without having to interpret the
start_timeentry 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 | bcQuoted 5 lines
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
Quoted 9 lines · Davidlohr Bueso
Quoted 4 lines · Alexey Dobriyan
Quoted 1 line · Davidlohr Bueso
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_timeentry 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
Signature · 1 line
[email protected] -- Speaking for myself only.
Quoted 6 lines · Andi Kleen
Quoted 4 lines · Davidlohr Bueso
Quoted 3 lines · Alexey Dobriyan
Quoted 1 line · Davidlohr Bueso
This patch exports a process's age, in seconds, adding a /proc/#/age file.
Quoted 9 lines
Quoted 5 lines
Quoted 1 line
What for?
I have not found any straight way to get the run time of a processes, without having to interpret the
start_timeentry 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
Quoted 2 lines
True, but there are also many other no-so-useful files under /proc that can also be replaced by userspace apps.
Example?
-andi
Signature · 1 line
[email protected] -- Speaking for myself only.
Quoted 4 lines · Andi Kleen
Quoted 2 lines
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
Quoted 9 lines · Davidlohr Bueso
Quoted 4 lines · Andi Kleen
Quoted 2 lines
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).
Quoted 7 lines · Américo Wang
Quoted 6 lines · Davidlohr Bueso
Quoted 4 lines · Andi Kleen
Quoted 2 lines
True, but there are also many other no-so-useful files under /proc that can also be replaced by userspace apps.
Example?
Quoted 9 lines
Quoted 3 lines
Off the top of my head:
/proc/cmdlineAre you kidding?
/proc/cmdlinescontains 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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html