From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ingo Molnar Subject: Re: [PATCH] kvm tools: Change method of retrieving process name Date: Tue, 9 Aug 2011 16:53:34 +0200 Message-ID: <20110809145331.GC28228@elte.hu> References: <1312885059-842-1-git-send-email-levinsasha928@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: penberg@kernel.org, psuriset@linux.vnet.ibm.com, asias.hejun@gmail.com, prasadjoshi124@gmail.com, gorcunov@gmail.com, kvm@vger.kernel.org To: Sasha Levin Return-path: Received: from mx3.mail.elte.hu ([157.181.1.138]:35575 "EHLO mx3.mail.elte.hu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751250Ab1HIOy3 (ORCPT ); Tue, 9 Aug 2011 10:54:29 -0400 Content-Disposition: inline In-Reply-To: <1312885059-842-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: * Sasha Levin wrote: > This patch changes './kvm list' to retrieve process name from > '/proc//stat' instead of '/proc//comm' as it appears the latter > does not exist by default on several systems. > > Reported-by: pradeep > Signed-off-by: Sasha Levin > --- > 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