From: Ingo Molnar <mingo@elte.hu>
To: Pekka Enberg <penberg@kernel.org>
Cc: Sasha Levin <levinsasha928@gmail.com>,
psuriset@linux.vnet.ibm.com, asias.hejun@gmail.com,
prasadjoshi124@gmail.com, gorcunov@gmail.com,
kvm@vger.kernel.org
Subject: Re: [PATCH] kvm tools: Change method of retrieving process name
Date: Tue, 9 Aug 2011 16:59:20 +0200 [thread overview]
Message-ID: <20110809145920.GD28228@elte.hu> (raw)
In-Reply-To: <CAOJsxLGPHkkgCx_Yz7YeGzstbEVN3Yg4N30b1QZNZk-XPFvMtw@mail.gmail.com>
* Pekka Enberg <penberg@kernel.org> wrote:
> On Tue, Aug 9, 2011 at 5:53 PM, Ingo Molnar <mingo@elte.hu> wrote:
> >
> > * Sasha Levin <levinsasha928@gmail.com> wrote:
> >
> >> This patch changes './kvm list' to retrieve process name from
> >> '/proc/<pid>/stat' instead of '/proc/<pid>/comm' as it appears the latter
> >> does not exist by default on several systems.
> >>
> >> Reported-by: pradeep <psuriset@linux.vnet.ibm.com>
> >> Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
> >> ---
> >> tools/kvm/builtin-list.c | 21 ++++++++++++++-------
> >> 1 files changed, 14 insertions(+), 7 deletions(-)
> >>
> >> diff --git a/tools/kvm/builtin-list.c b/tools/kvm/builtin-list.c
> >> index 2d37ecb..89a0465 100644
> >> --- a/tools/kvm/builtin-list.c
> >> +++ b/tools/kvm/builtin-list.c
> >> @@ -13,25 +13,32 @@
> >> static void print_guest(const char *name, int pid)
> >> {
> >> char proc_name[PATH_MAX];
> >> - char comm[sizeof(PROCESS_NAME)];
> >> - int fd;
> >> + char *comm = NULL;
> >> + FILE *fd;
> >>
> >> - sprintf(proc_name, "/proc/%d/comm", pid);
> >> - fd = open(proc_name, O_RDONLY);
> >> - if (fd <= 0)
> >> + sprintf(proc_name, "/proc/%d/stat", pid);
> >> + fd = fopen(proc_name, "r");
> >> + if (fd == NULL)
> >> goto cleanup;
> >
> > No, instead we should fall back to 'stat' if the 'comm' access fails.
> > The 'stat' field contains a lot more data and is thus slower - while
> > 'comm' only outputs the comm.
>
> Doh. I already merged the patch. Sasha, can you please send an
> incremental one to fix it up?
well, it's not bad code per se - the speedup probably isnt really
noticeable either - but we should do it nevertheless, out of
principle :)
Thanks,
Ingo
next prev parent reply other threads:[~2011-08-09 15:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-09 10:17 [PATCH] kvm tools: Change method of retrieving process name Sasha Levin
2011-08-09 14:53 ` Ingo Molnar
2011-08-09 14:56 ` Pekka Enberg
2011-08-09 14:59 ` Ingo Molnar [this message]
2011-08-09 15:02 ` Sasha Levin
2011-08-09 15:13 ` Pekka Enberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110809145920.GD28228@elte.hu \
--to=mingo@elte.hu \
--cc=asias.hejun@gmail.com \
--cc=gorcunov@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=levinsasha928@gmail.com \
--cc=penberg@kernel.org \
--cc=prasadjoshi124@gmail.com \
--cc=psuriset@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox