AF:
NF:0
PS:10
SRH:1
SFN:
DSR:
MID:<20070306110655.5bd47793@ripper.onstor.net>
CFG:
PT:0
S:andy.sharp@onstor.com
RQ:
SSV:onstor-exch02.onstor.net
NSV:
SSH:
R:<rendell.fong@onstor.com>
MAID:1
X-Sylpheed-Privacy-System:
X-Sylpheed-Sign:0
SCF:#mh/Mailbox/sent
RMID:#imap/andys@onstor.net@onstor-exch02.onstor.net/INBOX	0	BB375AF679D4A34E9CA8DFA650E2B04E0149E36E@onstor-exch02.onstor.net
X-Sylpheed-End-Special-Headers: 1
Date: Tue, 6 Mar 2007 11:08:25 -0800
From: Andrew Sharp <andy.sharp@onstor.com>
To: "Rendell Fong" <rendell.fong@onstor.com>
Subject: Re: popen() in BSD
Message-ID: <20070306110825.4be73328@ripper.onstor.net>
In-Reply-To: <BB375AF679D4A34E9CA8DFA650E2B04E0149E36E@onstor-exch02.onstor.net>
References: <20070306100320.328c8b4a@ripper.onstor.net>
	<BB375AF679D4A34E9CA8DFA650E2B04E0149E36E@onstor-exch02.onstor.net>
Organization: Onstor
X-Mailer: Sylpheed-Claws 2.6.0 (GTK+ 2.8.20; x86_64-pc-linux-gnu)
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit

It could be a problem in chassis not properly reaping it's children?

Cheers,

a

On Tue, 6 Mar 2007 10:18:14 -0800 "Rendell Fong"
<rendell.fong@onstor.com> wrote:

> That was my first thought, but I see can't any way that pclose can be
> skipped in this code unless popen failed (i.e. the file pointer was
> NULL) to begin with. Oh well, I'll just go with the creating and
> reading a temp file.
> 
> if ((fp = popen("/usr/local/agile/bin/chassis view ver", "r")) !=
> NULL) {
>             char tmp[80];
>             char *p;
> 
>             memset(tmp, 0, sizeof(tmp));
> 
>             while (!feof(fp))
>             {
>                 if (fgets(tmp, sizeof(tmp), fp) == NULL)
>                     break;
> 
>                 if ((p = strchr(tmp, '\n')) != NULL)
>                     *p = '\0';
> 
>                 if ((p = strstr(tmp, "Model number: ")) != NULL)
>                 {
>                     strncpy(prod_modelNo, p + strlen("Model number:
> "), CM_VER_STRING_LEN);
>                 }
>                 else
>                 if ((p = strstr(tmp, "System serial number: ")) !=
> NULL) {
>                     strncpy(prod_serialNo, p + strlen("System serial
> number: "),                            CM_VER_STRING_LEN);
>                 }
>                 else
>                 if ((p = strstr(tmp, "System revision: ")) != NULL)
>                 {
>                     strncpy(prod_revision, p + strlen("System
> revision: "),
>                             CM_VER_STRING_LEN);
>                 }
>                 else
>                 if ((p = strstr(tmp, "Board serial number: ")) !=
> NULL) {                     strncpy(prod_bdSerialNo, p +
> strlen("Board serial number: "),
>                             CM_VER_STRING_LEN);
>                 }
>                 else
>                 if ((p = strstr(tmp, "Board revision: ")) != NULL)
>                 {
>                     strncpy(prod_bdRevision, p + strlen("Board
> revision: "),
>                             CM_VER_STRING_LEN);
>                 }
>             }
>     pclose(fp);
> }
> 
> Thanks,
> Rendell
> 
> 
> -----Original Message-----
> From: Andy Sharp 
> Sent: Tuesday, March 06, 2007 10:03 AM
> To: Rendell Fong
> Subject: Re: popen() in BSD
> 
> Sounds like you're not using pclose() to close the stream returned
> from popen().  Lingering processes are there because they have not
> been reaped.  That will only happen if you have failed to close the
> stream with pclose.  Or perhaps there is a bug in C library or
> OpenBSD, but what are the chances of that?
> 
> Cheers,
> 
> a
> 
> On Tue, 6 Mar 2007 09:52:22 -0800 "Rendell Fong"
> <rendell.fong@onstor.com> wrote:
> 
> > Is anyone aware of issues with using popen/pclose?
> > When I use it in my code, I've noticed a side effect where
> > sometimes a zombie process is left lingering.
> > It only occurs sometimes when it is used.
> > 
> > eng59# ps -ax | grep Z
> >  1362 ??  Z       0:00.00 (sh)
> >  7240 ??  Z       0:00.00 (sh)
> > 15137 ??  Z       0:00.00 (sh)
> > 24215 ??  Z       0:00.00 (sh)
> > 30321 ??  Z       0:00.00 (sh)
> > eng59#
> > 
> > I'm fairly certain that popen is the cause of these zombie processes
> > because replacing it with the equivalent functionality (system call
> > and fopen/fclose) makes this problem go away.
> > 
