* [PATCH] proc: let task status file print utime and stime.
@ 2009-08-15 14:36 KOSAKI Motohiro
2009-08-17 2:38 ` Amerigo Wang
0 siblings, 1 reply; 10+ messages in thread
From: KOSAKI Motohiro @ 2009-08-15 14:36 UTC (permalink / raw)
To: LKML; +Cc: kosaki.motohiro, Tatsuhiro Aoshima, YOSHIFUJI Hideaki
From: Tatsuhiro Aoshima <tatsu.pc@gmail.com>
Subject: [PATCH] proc: let task status file print utime and stime.
The task status file in proc file system did not contain
user-time and system-time. Thus, users could not get
those information of running task easily. I think
these values should be provived in human readable format.
By this patch, users can get stime and utime very easily.
Signed-off-by: Tatsuhiro Aoshima <tatsu.pc@gmail.com>
Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
---
fs/proc/array.c | 11 +++++++++--
1 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/fs/proc/array.c b/fs/proc/array.c
index 725a650..29afa68 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -162,6 +162,7 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
struct fdtable *fdt = NULL;
const struct cred *cred;
pid_t ppid, tpid;
+ struct timeval utime, stime;
rcu_read_lock();
ppid = pid_alive(p) ?
@@ -173,6 +174,8 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
tpid = task_pid_nr_ns(tracer, ns);
}
cred = get_cred((struct cred *) __task_cred(p));
+ cputime_to_timeval(task_utime(p), &utime);
+ cputime_to_timeval(task_stime(p), &stime);
seq_printf(m,
"State:\t%s\n"
"Tgid:\t%d\n"
@@ -180,13 +183,17 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
"PPid:\t%d\n"
"TracerPid:\t%d\n"
"Uid:\t%d\t%d\t%d\t%d\n"
- "Gid:\t%d\t%d\t%d\t%d\n",
+ "Gid:\t%d\t%d\t%d\t%d\n"
+ "Utime:\t%lu.%06lu\n"
+ "Stime:\t%lu.%06lu\n",
get_task_state(p),
task_tgid_nr_ns(p, ns),
pid_nr_ns(pid, ns),
ppid, tpid,
cred->uid, cred->euid, cred->suid, cred->fsuid,
- cred->gid, cred->egid, cred->sgid, cred->fsgid);
+ cred->gid, cred->egid, cred->sgid, cred->fsgid,
+ (unsigned long) utime.tv_sec, (unsigned long) utime.tv_usec,
+ (unsigned long) stime.tv_sec, (unsigned long) stime.tv_usec);
task_lock(p);
if (p->files)
--
1.4.4.4
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] proc: let task status file print utime and stime.
2009-08-15 14:36 [PATCH] proc: let task status file print utime and stime KOSAKI Motohiro
@ 2009-08-17 2:38 ` Amerigo Wang
2009-08-17 2:42 ` KAMEZAWA Hiroyuki
0 siblings, 1 reply; 10+ messages in thread
From: Amerigo Wang @ 2009-08-17 2:38 UTC (permalink / raw)
To: KOSAKI Motohiro; +Cc: LKML, Tatsuhiro Aoshima, YOSHIFUJI Hideaki
On Sat, Aug 15, 2009 at 11:36:41PM +0900, KOSAKI Motohiro wrote:
>From: Tatsuhiro Aoshima <tatsu.pc@gmail.com>
>Subject: [PATCH] proc: let task status file print utime and stime.
>
>The task status file in proc file system did not contain
>user-time and system-time. Thus, users could not get
>those information of running task easily. I think
>these values should be provived in human readable format.
>By this patch, users can get stime and utime very easily.
Why? /proc/<pid>/stat already has these.
>
>Signed-off-by: Tatsuhiro Aoshima <tatsu.pc@gmail.com>
>Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
>Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
>---
> fs/proc/array.c | 11 +++++++++--
> 1 files changed, 9 insertions(+), 2 deletions(-)
>
>diff --git a/fs/proc/array.c b/fs/proc/array.c
>index 725a650..29afa68 100644
>--- a/fs/proc/array.c
>+++ b/fs/proc/array.c
>@@ -162,6 +162,7 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
> struct fdtable *fdt = NULL;
> const struct cred *cred;
> pid_t ppid, tpid;
>+ struct timeval utime, stime;
>
> rcu_read_lock();
> ppid = pid_alive(p) ?
>@@ -173,6 +174,8 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
> tpid = task_pid_nr_ns(tracer, ns);
> }
> cred = get_cred((struct cred *) __task_cred(p));
>+ cputime_to_timeval(task_utime(p), &utime);
>+ cputime_to_timeval(task_stime(p), &stime);
> seq_printf(m,
> "State:\t%s\n"
> "Tgid:\t%d\n"
>@@ -180,13 +183,17 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
> "PPid:\t%d\n"
> "TracerPid:\t%d\n"
> "Uid:\t%d\t%d\t%d\t%d\n"
>- "Gid:\t%d\t%d\t%d\t%d\n",
>+ "Gid:\t%d\t%d\t%d\t%d\n"
>+ "Utime:\t%lu.%06lu\n"
>+ "Stime:\t%lu.%06lu\n",
> get_task_state(p),
> task_tgid_nr_ns(p, ns),
> pid_nr_ns(pid, ns),
> ppid, tpid,
> cred->uid, cred->euid, cred->suid, cred->fsuid,
>- cred->gid, cred->egid, cred->sgid, cred->fsgid);
>+ cred->gid, cred->egid, cred->sgid, cred->fsgid,
>+ (unsigned long) utime.tv_sec, (unsigned long) utime.tv_usec,
>+ (unsigned long) stime.tv_sec, (unsigned long) stime.tv_usec);
>
> task_lock(p);
> if (p->files)
>--
>1.4.4.4
>
>
>
>--
>To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at http://vger.kernel.org/majordomo-info.html
>Please read the FAQ at http://www.tux.org/lkml/
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] proc: let task status file print utime and stime.
2009-08-17 2:38 ` Amerigo Wang
@ 2009-08-17 2:42 ` KAMEZAWA Hiroyuki
2009-08-17 6:18 ` Amerigo Wang
0 siblings, 1 reply; 10+ messages in thread
From: KAMEZAWA Hiroyuki @ 2009-08-17 2:42 UTC (permalink / raw)
To: Amerigo Wang; +Cc: KOSAKI Motohiro, LKML, Tatsuhiro Aoshima, YOSHIFUJI Hideaki
On Mon, 17 Aug 2009 10:38:02 +0800
Amerigo Wang <xiyou.wangcong@gmail.com> wrote:
> On Sat, Aug 15, 2009 at 11:36:41PM +0900, KOSAKI Motohiro wrote:
> >From: Tatsuhiro Aoshima <tatsu.pc@gmail.com>
> >Subject: [PATCH] proc: let task status file print utime and stime.
> >
> >The task status file in proc file system did not contain
> >user-time and system-time. Thus, users could not get
> >those information of running task easily. I think
> >these values should be provived in human readable format.
> >By this patch, users can get stime and utime very easily.
>
>
> Why? /proc/<pid>/stat already has these.
>
I wonder /proc/<pid>/stat is unreadable for usual human.
Most of ents in /proc/<pid>/status is duplicated output of
some other files(i.e. /proc/<pid>/stat) and /proc/<pid>/status is
for human readble format.
In another thinking, in old days, /proc/<pid>/stat was enough because most of
users uses scanf() or some C langage to read fixed-format data.
/proc/<pid>/status is useful for some script languages which has
good parser per line.
?
-Kame
>
> >
> >Signed-off-by: Tatsuhiro Aoshima <tatsu.pc@gmail.com>
> >Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
> >Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> >---
> > fs/proc/array.c | 11 +++++++++--
> > 1 files changed, 9 insertions(+), 2 deletions(-)
> >
> >diff --git a/fs/proc/array.c b/fs/proc/array.c
> >index 725a650..29afa68 100644
> >--- a/fs/proc/array.c
> >+++ b/fs/proc/array.c
> >@@ -162,6 +162,7 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
> > struct fdtable *fdt = NULL;
> > const struct cred *cred;
> > pid_t ppid, tpid;
> >+ struct timeval utime, stime;
> >
> > rcu_read_lock();
> > ppid = pid_alive(p) ?
> >@@ -173,6 +174,8 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
> > tpid = task_pid_nr_ns(tracer, ns);
> > }
> > cred = get_cred((struct cred *) __task_cred(p));
> >+ cputime_to_timeval(task_utime(p), &utime);
> >+ cputime_to_timeval(task_stime(p), &stime);
> > seq_printf(m,
> > "State:\t%s\n"
> > "Tgid:\t%d\n"
> >@@ -180,13 +183,17 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
> > "PPid:\t%d\n"
> > "TracerPid:\t%d\n"
> > "Uid:\t%d\t%d\t%d\t%d\n"
> >- "Gid:\t%d\t%d\t%d\t%d\n",
> >+ "Gid:\t%d\t%d\t%d\t%d\n"
> >+ "Utime:\t%lu.%06lu\n"
> >+ "Stime:\t%lu.%06lu\n",
> > get_task_state(p),
> > task_tgid_nr_ns(p, ns),
> > pid_nr_ns(pid, ns),
> > ppid, tpid,
> > cred->uid, cred->euid, cred->suid, cred->fsuid,
> >- cred->gid, cred->egid, cred->sgid, cred->fsgid);
> >+ cred->gid, cred->egid, cred->sgid, cred->fsgid,
> >+ (unsigned long) utime.tv_sec, (unsigned long) utime.tv_usec,
> >+ (unsigned long) stime.tv_sec, (unsigned long) stime.tv_usec);
> >
> > task_lock(p);
> > if (p->files)
> >--
> >1.4.4.4
> >
> >
> >
> >--
> >To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> >the body of a message to majordomo@vger.kernel.org
> >More majordomo info at http://vger.kernel.org/majordomo-info.html
> >Please read the FAQ at http://www.tux.org/lkml/
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] proc: let task status file print utime and stime.
2009-08-17 2:42 ` KAMEZAWA Hiroyuki
@ 2009-08-17 6:18 ` Amerigo Wang
2009-08-17 6:22 ` KAMEZAWA Hiroyuki
0 siblings, 1 reply; 10+ messages in thread
From: Amerigo Wang @ 2009-08-17 6:18 UTC (permalink / raw)
To: KAMEZAWA Hiroyuki
Cc: Amerigo Wang, KOSAKI Motohiro, LKML, Tatsuhiro Aoshima,
YOSHIFUJI Hideaki
On Mon, Aug 17, 2009 at 11:42:42AM +0900, KAMEZAWA Hiroyuki wrote:
>On Mon, 17 Aug 2009 10:38:02 +0800
>Amerigo Wang <xiyou.wangcong@gmail.com> wrote:
>
>> On Sat, Aug 15, 2009 at 11:36:41PM +0900, KOSAKI Motohiro wrote:
>> >From: Tatsuhiro Aoshima <tatsu.pc@gmail.com>
>> >Subject: [PATCH] proc: let task status file print utime and stime.
>> >
>> >The task status file in proc file system did not contain
>> >user-time and system-time. Thus, users could not get
>> >those information of running task easily. I think
>> >these values should be provived in human readable format.
>> >By this patch, users can get stime and utime very easily.
>>
>>
>> Why? /proc/<pid>/stat already has these.
>>
>
>I wonder /proc/<pid>/stat is unreadable for usual human.
>Most of ents in /proc/<pid>/status is duplicated output of
>some other files(i.e. /proc/<pid>/stat) and /proc/<pid>/status is
>for human readble format.
Ah... in fact, I expected 'ps' can report this, however, surprisingly
it doesn't have this, at least not what I expect (unless I miss
something obvious).
>
>In another thinking, in old days, /proc/<pid>/stat was enough because most of
>users uses scanf() or some C langage to read fixed-format data.
>/proc/<pid>/status is useful for some script languages which has
>good parser per line.
>
Well... I think this work should be left to 'ps', e.g.
ps -o pid,utime,stime
'ps' is responsible to read /proc/<pid>/stat for the user.
Thanks.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] proc: let task status file print utime and stime.
2009-08-17 6:18 ` Amerigo Wang
@ 2009-08-17 6:22 ` KAMEZAWA Hiroyuki
2009-08-17 6:32 ` Amerigo Wang
0 siblings, 1 reply; 10+ messages in thread
From: KAMEZAWA Hiroyuki @ 2009-08-17 6:22 UTC (permalink / raw)
To: Amerigo Wang; +Cc: KOSAKI Motohiro, LKML, Tatsuhiro Aoshima, YOSHIFUJI Hideaki
On Mon, 17 Aug 2009 14:18:21 +0800
Amerigo Wang <xiyou.wangcong@gmail.com> wrote:
> Ah... in fact, I expected 'ps' can report this, however, surprisingly
> it doesn't have this, at least not what I expect (unless I miss
> something obvious).
>
>
> >
> >In another thinking, in old days, /proc/<pid>/stat was enough because most of
> >users uses scanf() or some C langage to read fixed-format data.
> >/proc/<pid>/status is useful for some script languages which has
> >good parser per line.
> >
>
> Well... I think this work should be left to 'ps', e.g.
>
> ps -o pid,utime,stime
>
> 'ps' is responsible to read /proc/<pid>/stat for the user.
>
Hmm, personally, I don't like 'ps' and its unified filter.
When I want to know status of a process of PID,
# ps -o pid,utime,stime PID
'ps' scans *all* process and filter PID. (try #strace ps)
I like checking /proc/<pid>/<something> without 'ps' in an environment
where thousands of processes runs.
Thanks,
-Kame
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] proc: let task status file print utime and stime.
2009-08-17 6:22 ` KAMEZAWA Hiroyuki
@ 2009-08-17 6:32 ` Amerigo Wang
2009-08-17 6:32 ` KAMEZAWA Hiroyuki
0 siblings, 1 reply; 10+ messages in thread
From: Amerigo Wang @ 2009-08-17 6:32 UTC (permalink / raw)
To: KAMEZAWA Hiroyuki
Cc: Amerigo Wang, KOSAKI Motohiro, LKML, Tatsuhiro Aoshima,
YOSHIFUJI Hideaki
On Mon, Aug 17, 2009 at 03:22:06PM +0900, KAMEZAWA Hiroyuki wrote:
>On Mon, 17 Aug 2009 14:18:21 +0800
>Amerigo Wang <xiyou.wangcong@gmail.com> wrote:
>
>> Ah... in fact, I expected 'ps' can report this, however, surprisingly
>> it doesn't have this, at least not what I expect (unless I miss
>> something obvious).
>>
>>
>> >
>> >In another thinking, in old days, /proc/<pid>/stat was enough because most of
>> >users uses scanf() or some C langage to read fixed-format data.
>> >/proc/<pid>/status is useful for some script languages which has
>> >good parser per line.
>> >
>>
>> Well... I think this work should be left to 'ps', e.g.
>>
>> ps -o pid,utime,stime
>>
>> 'ps' is responsible to read /proc/<pid>/stat for the user.
>>
>Hmm, personally, I don't like 'ps' and its unified filter.
>
>When I want to know status of a process of PID,
># ps -o pid,utime,stime PID
>
>'ps' scans *all* process and filter PID. (try #strace ps)
>I like checking /proc/<pid>/<something> without 'ps' in an environment
>where thousands of processes runs.
Sure, we already have '-p' for 'ps', e.g.
ps -p 1 -o pid,user,comm
Enjoy. :-)
Anyway, I would like to see 'ps' to have 'utime,stime' field, on
my machine, its output for 'utime,stime' looks wrong.
Maybe we should Cc procps developers?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] proc: let task status file print utime and stime.
2009-08-17 6:32 ` Amerigo Wang
@ 2009-08-17 6:32 ` KAMEZAWA Hiroyuki
2009-08-17 8:34 ` Amerigo Wang
0 siblings, 1 reply; 10+ messages in thread
From: KAMEZAWA Hiroyuki @ 2009-08-17 6:32 UTC (permalink / raw)
To: Amerigo Wang; +Cc: KOSAKI Motohiro, LKML, Tatsuhiro Aoshima, YOSHIFUJI Hideaki
On Mon, 17 Aug 2009 14:32:02 +0800
Amerigo Wang <xiyou.wangcong@gmail.com> wrote:
> On Mon, Aug 17, 2009 at 03:22:06PM +0900, KAMEZAWA Hiroyuki wrote:
> >On Mon, 17 Aug 2009 14:18:21 +0800
> >Amerigo Wang <xiyou.wangcong@gmail.com> wrote:
> >
> >> Ah... in fact, I expected 'ps' can report this, however, surprisingly
> >> it doesn't have this, at least not what I expect (unless I miss
> >> something obvious).
> >>
> >>
> >> >
> >> >In another thinking, in old days, /proc/<pid>/stat was enough because most of
> >> >users uses scanf() or some C langage to read fixed-format data.
> >> >/proc/<pid>/status is useful for some script languages which has
> >> >good parser per line.
> >> >
> >>
> >> Well... I think this work should be left to 'ps', e.g.
> >>
> >> ps -o pid,utime,stime
> >>
> >> 'ps' is responsible to read /proc/<pid>/stat for the user.
> >>
> >Hmm, personally, I don't like 'ps' and its unified filter.
> >
> >When I want to know status of a process of PID,
> ># ps -o pid,utime,stime PID
> >
> >'ps' scans *all* process and filter PID. (try #strace ps)
> >I like checking /proc/<pid>/<something> without 'ps' in an environment
> >where thousands of processes runs.
>
> Sure, we already have '-p' for 'ps', e.g.
>
> ps -p 1 -o pid,user,comm
>
> Enjoy. :-)
I said it's verrrrry slow.
>
> Anyway, I would like to see 'ps' to have 'utime,stime' field, on
> my machine, its output for 'utime,stime' looks wrong.
>
> Maybe we should Cc procps developers?
ya, maybe. it's good to be CCed.
BTW, why all other status
Name: cat
State: R (running)
Tgid: 7068
Pid: 7068
PPid: 6115
TracerPid: 0
Uid: 500 500 500 500
Gid: 500 500 500 500
FDSize: 256
Groups: 500
are allowed to be duplicated ?
I bet stime.utime will be used more often than TracerPid/FDSize/ ;)
Thanks,
-Kame
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] proc: let task status file print utime and stime.
2009-08-17 6:32 ` KAMEZAWA Hiroyuki
@ 2009-08-17 8:34 ` Amerigo Wang
2009-08-18 16:27 ` KOSAKI Motohiro
0 siblings, 1 reply; 10+ messages in thread
From: Amerigo Wang @ 2009-08-17 8:34 UTC (permalink / raw)
To: KAMEZAWA Hiroyuki
Cc: Amerigo Wang, KOSAKI Motohiro, LKML, Tatsuhiro Aoshima,
YOSHIFUJI Hideaki, albert
On Mon, Aug 17, 2009 at 03:32:53PM +0900, KAMEZAWA Hiroyuki wrote:
>On Mon, 17 Aug 2009 14:32:02 +0800
>Amerigo Wang <xiyou.wangcong@gmail.com> wrote:
>
>> On Mon, Aug 17, 2009 at 03:22:06PM +0900, KAMEZAWA Hiroyuki wrote:
>> >On Mon, 17 Aug 2009 14:18:21 +0800
>> >Amerigo Wang <xiyou.wangcong@gmail.com> wrote:
>> >
>> >> Ah... in fact, I expected 'ps' can report this, however, surprisingly
>> >> it doesn't have this, at least not what I expect (unless I miss
>> >> something obvious).
>> >>
>> >>
>> >> >
>> >> >In another thinking, in old days, /proc/<pid>/stat was enough because most of
>> >> >users uses scanf() or some C langage to read fixed-format data.
>> >> >/proc/<pid>/status is useful for some script languages which has
>> >> >good parser per line.
>> >> >
>> >>
>> >> Well... I think this work should be left to 'ps', e.g.
>> >>
>> >> ps -o pid,utime,stime
>> >>
>> >> 'ps' is responsible to read /proc/<pid>/stat for the user.
>> >>
>> >Hmm, personally, I don't like 'ps' and its unified filter.
>> >
>> >When I want to know status of a process of PID,
>> ># ps -o pid,utime,stime PID
>> >
>> >'ps' scans *all* process and filter PID. (try #strace ps)
>> >I like checking /proc/<pid>/<something> without 'ps' in an environment
>> >where thousands of processes runs.
>>
>> Sure, we already have '-p' for 'ps', e.g.
>>
>> ps -p 1 -o pid,user,comm
>>
>> Enjoy. :-)
>I said it's verrrrry slow.
Hmm, for me it looks like that 'ps' should be fixed...
I haven't checked the source code of 'ps', but I don't think
this is O(n) if '-p' is specified. If we just use something
like 'test -d /proc/<pid>' it would be O(1).
>
>>
>> Anyway, I would like to see 'ps' to have 'utime,stime' field, on
>> my machine, its output for 'utime,stime' looks wrong.
>>
>> Maybe we should Cc procps developers?
>ya, maybe. it's good to be CCed.
Done. Albert?
>
>
>BTW, why all other status
>Name: cat
>State: R (running)
>Tgid: 7068
>Pid: 7068
>PPid: 6115
>TracerPid: 0
>Uid: 500 500 500 500
>Gid: 500 500 500 500
>FDSize: 256
>Groups: 500
>
>are allowed to be duplicated ?
I don't know... :( I still prefer to use 'ps'.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] proc: let task status file print utime and stime.
2009-08-17 8:34 ` Amerigo Wang
@ 2009-08-18 16:27 ` KOSAKI Motohiro
0 siblings, 0 replies; 10+ messages in thread
From: KOSAKI Motohiro @ 2009-08-18 16:27 UTC (permalink / raw)
To: Amerigo Wang
Cc: kosaki.motohiro, KAMEZAWA Hiroyuki, LKML, Tatsuhiro Aoshima,
YOSHIFUJI Hideaki, albert
Hi
> On Mon, Aug 17, 2009 at 03:32:53PM +0900, KAMEZAWA Hiroyuki wrote:
> >On Mon, 17 Aug 2009 14:32:02 +0800
> >Amerigo Wang <xiyou.wangcong@gmail.com> wrote:
> >
> >> On Mon, Aug 17, 2009 at 03:22:06PM +0900, KAMEZAWA Hiroyuki wrote:
> >> >On Mon, 17 Aug 2009 14:18:21 +0800
> >> >Amerigo Wang <xiyou.wangcong@gmail.com> wrote:
> >> >
> >> >> Ah... in fact, I expected 'ps' can report this, however, surprisingly
> >> >> it doesn't have this, at least not what I expect (unless I miss
> >> >> something obvious).
Yes, hehe, I also expected so :-)
> >> >> >In another thinking, in old days, /proc/<pid>/stat was enough because most of
> >> >> >users uses scanf() or some C langage to read fixed-format data.
> >> >> >/proc/<pid>/status is useful for some script languages which has
> >> >> >good parser per line.
> >> >>
> >> >> Well... I think this work should be left to 'ps', e.g.
> >> >>
> >> >> ps -o pid,utime,stime
> >> >>
> >> >> 'ps' is responsible to read /proc/<pid>/stat for the user.
>
> >> >Hmm, personally, I don't like 'ps' and its unified filter.
> >> >
> >> >When I want to know status of a process of PID,
> >> ># ps -o pid,utime,stime PID
> >> >
> >> >'ps' scans *all* process and filter PID. (try #strace ps)
> >> >I like checking /proc/<pid>/<something> without 'ps' in an environment
> >> >where thousands of processes runs.
> >>
> >> Sure, we already have '-p' for 'ps', e.g.
> >>
> >> ps -p 1 -o pid,user,comm
> >>
> >> Enjoy. :-)
> >I said it's verrrrry slow.
>
>
> Hmm, for me it looks like that 'ps' should be fixed...
>
> I haven't checked the source code of 'ps', but I don't think
> this is O(n) if '-p' is specified. If we just use something
> like 'test -d /proc/<pid>' it would be O(1).
I think kamezawa-san is right.
procps always read ALL proc. and after, it check pid by want_this_proc().
That's obviously O(n) ;-)
---------------------------------------------------------------
static void simple_spew(void){
(snip)
switch(thread_flags & (TF_show_proc|TF_loose_tasks|TF_show_task)){
case TF_show_proc: // normal non-thread output
while(readproc(ptp,&buf)){
if(want_this_proc(&buf)){
show_one_proc(&buf, proc_format_list);
}
if(buf.cmdline) free((void*)*buf.cmdline); // ought to reuse
if(buf.environ) free((void*)*buf.environ); // ought to reuse
}
break;
---------------------------------------------------------------
> >> Anyway, I would like to see 'ps' to have 'utime,stime' field, on
> >> my machine, its output for 'utime,stime' looks wrong.
> >>
> >> Maybe we should Cc procps developers?
> >ya, maybe. it's good to be CCed.
>
> Done. Albert?
Albert? What do you think?
> >BTW, why all other status
> >Name: cat
> >State: R (running)
> >Tgid: 7068
> >Pid: 7068
> >PPid: 6115
> >TracerPid: 0
> >Uid: 500 500 500 500
> >Gid: 500 500 500 500
> >FDSize: 256
> >Groups: 500
> >
> >are allowed to be duplicated ?
>
>
> I don't know... :( I still prefer to use 'ps'.
Do their have any exclusive relation?
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH] proc: let task status file print utime and stime.
@ 2009-08-29 7:20 Tatsuhiro Aoshima
0 siblings, 0 replies; 10+ messages in thread
From: Tatsuhiro Aoshima @ 2009-08-29 7:20 UTC (permalink / raw)
To: linux-kernel; +Cc: tatsu.pc, yoshfuji, kosaki.motohiro
From: Tatsuhiro Aoshima <tatsu.pc@gmail.com>
Subject: [PATCH] proc: let task status file print utime and stime.
The task status file in proc file system did not contain
user-time and system-time. Thus, users could not get
those information of running task easily. I think
these values should be provived in human readable format.
By this patch, users can get stime and utime very easily.
Signed-off-by: Tatsuhiro Aoshima <tatsu.pc@gmail.com>
Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
---
fs/proc/array.c | 11 +++++++++--
1 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/fs/proc/array.c b/fs/proc/array.c
index 725a650..29afa68 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -162,6 +162,7 @@ static inline void task_state(struct seq_file *m,
struct pid_namespace *ns,
struct fdtable *fdt = NULL;
const struct cred *cred;
pid_t ppid, tpid;
+ struct timeval utime, stime;
rcu_read_lock();
ppid = pid_alive(p) ?
@@ -173,6 +174,8 @@ static inline void task_state(struct seq_file *m,
struct pid_namespace *ns,
tpid = task_pid_nr_ns(tracer, ns);
}
cred = get_cred((struct cred *) __task_cred(p));
+ cputime_to_timeval(task_utime(p), &utime);
+ cputime_to_timeval(task_stime(p), &stime);
seq_printf(m,
"State:\t%s\n"
"Tgid:\t%d\n"
@@ -180,13 +183,17 @@ static inline void task_state(struct seq_file
*m, struct pid_namespace *ns,
"PPid:\t%d\n"
"TracerPid:\t%d\n"
"Uid:\t%d\t%d\t%d\t%d\n"
- "Gid:\t%d\t%d\t%d\t%d\n",
+ "Gid:\t%d\t%d\t%d\t%d\n"
+ "Utime:\t%lu.%06lu\n"
+ "Stime:\t%lu.%06lu\n",
get_task_state(p),
task_tgid_nr_ns(p, ns),
pid_nr_ns(pid, ns),
ppid, tpid,
cred->uid, cred->euid, cred->suid, cred->fsuid,
- cred->gid, cred->egid, cred->sgid, cred->fsgid);
+ cred->gid, cred->egid, cred->sgid, cred->fsgid,
+ (unsigned long) utime.tv_sec, (unsigned long) utime.tv_usec,
+ (unsigned long) stime.tv_sec, (unsigned long) stime.tv_usec);
task_lock(p);
if (p->files)
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2009-08-29 7:27 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-15 14:36 [PATCH] proc: let task status file print utime and stime KOSAKI Motohiro
2009-08-17 2:38 ` Amerigo Wang
2009-08-17 2:42 ` KAMEZAWA Hiroyuki
2009-08-17 6:18 ` Amerigo Wang
2009-08-17 6:22 ` KAMEZAWA Hiroyuki
2009-08-17 6:32 ` Amerigo Wang
2009-08-17 6:32 ` KAMEZAWA Hiroyuki
2009-08-17 8:34 ` Amerigo Wang
2009-08-18 16:27 ` KOSAKI Motohiro
2009-08-29 7:20 Tatsuhiro Aoshima
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®