From: Ingo Molnar <mingo@elte.hu>
To: Sasha Levin <levinsasha928@gmail.com>
Cc: penberg@kernel.org, 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:53:34 +0200 [thread overview]
Message-ID: <20110809145331.GC28228@elte.hu> (raw)
In-Reply-To: <1312885059-842-1-git-send-email-levinsasha928@gmail.com>
* 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.
Thanks,
Ingo
next prev parent reply other threads:[~2011-08-09 14:54 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 [this message]
2011-08-09 14:56 ` Pekka Enberg
2011-08-09 14:59 ` Ingo Molnar
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=20110809145331.GC28228@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