[28891] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 135 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 14 03:10:53 2007

Date: Wed, 14 Feb 2007 00:09:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 14 Feb 2007     Volume: 11 Number: 135

Today's topics:
        Bind 9 administration module(s) Dan.Rode@gmail.com
        Continue to Search file after matching a value <deadpickle@gmail.com>
    Re: Continue to Search file after matching a value xhoster@gmail.com
    Re: Continue to Search file after matching a value usenet@DavidFilmer.com
    Re: Continue to Search file after matching a value <tadmc@augustmail.com>
    Re: Continue to Search file after matching a value <tadmc@augustmail.com>
    Re: How to get table from some html <bik.mido@tiscalinet.it>
        Lazy evaluation? <hoelz@wisc.edu>
        loading modules run test <mmccaws@comcast.net>
    Re: loading modules run test <attn.steven.kuo@gmail.com>
    Re: loading modules run test <mmccaws@comcast.net>
    Re: read from STDIN <joe@inwap.com>
    Re: set "From" header <greg.ferguson@icrossing.com>
        waitpid woes on Solaris, Perl 5.8.8 <ad_101@yahoo.com>
    Re: waitpid woes on Solaris, Perl 5.8.8 xhoster@gmail.com
    Re: works now ! was: bypass shell - pipe into child pid <rvtol+news@isolution.nl>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 13 Feb 2007 21:09:38 -0800
From: Dan.Rode@gmail.com
Subject: Bind 9 administration module(s)
Message-Id: <1171429778.941131.189330@v33g2000cwv.googlegroups.com>

Many years ago I wrote a simple perl wrapper for bind 4.x. Now I need
to develop a set of scripts to front-end most DNS administration
tasks. My old script is not up to the task and not even useful as a
starting point. I have a couple hundred zone files.

Here's what I *think* I want to do.
1) Store everything in a mysql DB
2) Run from the master but also manage the slaves' named.conf files
(code not process)
3) Create named.conf and zone files on the fly as edits are made
(ensures files match DB records)
4) Manage forward and reverse records
5) Manage zone files (header)
6) Syntax and error checking
7) Web interface
8) Limit scope to Bind 9.x on UNIX/Linux

I don't want to reinvent the wheel. I have been searching CPAN and not
coming up with much. I found peices and parts much of it old and
incomplete. One note, I am fairly weak when it comes to Perl OO
programing, but I'll learn.

I am open to any sugestions, but I am especially in need of advice
concerning modules and scripts I can incorporate. Failing that, I'll
write it from the ground up and I'll gladly accept advice on that as
well.

Regards,

Dan Rode



------------------------------

Date: 13 Feb 2007 14:35:27 -0800
From: "deadpickle" <deadpickle@gmail.com>
Subject: Continue to Search file after matching a value
Message-Id: <1171406127.055878.67310@m58g2000cwm.googlegroups.com>

This is what I want the program to do:
1. Read in a file containing:
KBQP 071845Z AUTO 35003KT 7SM OVC012 14/12 A3018 RMK AO2=
KBQP 071905Z AUTO 35003KT 7SM OVC012 14/12 A3018 RMK AO2=
KHLR 071856Z AUTO 19010KT 10SM CLR 22/13 A3007 RMK AO2 SLP179
KBQP 071925Z AUTO 35003KT 7SM OVC012 14/12 A3018 RMK AO2=
2. Search for strings beginning with K at the beginning
EXAMPLE:     next unless $obs =~ m/^(K)/;
3. When they are found load them into an array
EXAMPLE:     my @a = split(" ", $obs);
4. Next, continue to search the file. But instead of searching for any
string beginning with K it instead searches for and string beginning
with the first four letters of the station ID.
EXAMPLE:     First time through finds that $a[0] = KBQP
                      Continues through the file until it finds
another KBQP
5. After it has found another station ID with the same name as shown
in #4, it then checks the next value in BOTH arrays and compares them.
The object is to see which string is the newest.
6. The newer string gets wrote to the array and the program continues
to search for the same ID.
7. If no other similar IDs are found, go back to step 1.

The flow should look something like this:
Search for "K"
Found "KBQP" -> Load into array
Search for "KBQP"
Found "KBQP" -> comparing times of the observations
Second "KBQP" found is newer -> replacing the array with newer "KBQP"
Search for "KBQP"
If No newer "KBQP" found -> Search For "K"

I hope this is clear. My problem is that I have no clue how to do this
after step 3. Any help would be appreciated.

Code So far:
==============================================================
use strict;
use warnings;
$\ = "\n";
my $wmo = "07020719f.wmo";
open OUT,'>', 'sub.txt' or die "cannot open 'sub.txt' $!";
open WMO, '<',  $wmo;
while (my $obs = <WMO>) {
	next unless $obs =~ m/^(K)/;
	my @a = split(" ", $obs);


}
close OUT;



------------------------------

Date: 13 Feb 2007 23:43:14 GMT
From: xhoster@gmail.com
Subject: Re: Continue to Search file after matching a value
Message-Id: <20070213184408.848$LM@newsreader.com>

"deadpickle" <deadpickle@gmail.com> wrote:
> This is what I want the program to do:
> 1. Read in a file containing:
> KBQP 071845Z AUTO 35003KT 7SM OVC012 14/12 A3018 RMK AO2=
> KBQP 071905Z AUTO 35003KT 7SM OVC012 14/12 A3018 RMK AO2=
> KHLR 071856Z AUTO 19010KT 10SM CLR 22/13 A3007 RMK AO2 SLP179
> KBQP 071925Z AUTO 35003KT 7SM OVC012 14/12 A3018 RMK AO2=
> 2. Search for strings beginning with K at the beginning

In your example, that is all of them.

> EXAMPLE:     next unless $obs =~ m/^(K)/;
> 3. When they are found load them into an array
> EXAMPLE:     my @a = split(" ", $obs);
> 4. Next, continue to search the file. But instead of searching for any
> string beginning with K it instead searches for and string beginning
> with the first four letters of the station ID.

So then "last" out of the loop and start a different loop.

> EXAMPLE:     First time through finds that $a[0] = KBQP
>                       Continues through the file until it finds
> another KBQP
> 5. After it has found another station ID with the same name as shown
> in #4, it then checks the next value in BOTH arrays and compares them.
> The object is to see which string is the newest.
> 6. The newer string gets wrote to the array and the program continues
> to search for the same ID.
> 7. If no other similar IDs are found, go back to step 1.

"similar" ne "same".  Which do you want?

At this point, You've reached the end of the file, so how does one go back
to step 1?  There is nothing left to process.  Do you have to rewind in the
file to some previously remembered landmark?  If so, see "tell" and "seek".

But really, if you would need to rewind, I think you are going about this
fundamentally the wrong way.  Use a hash on the station name, and store
in it the "newest" string encountered so far.  At the end, print out all
these station/string pairs.

> Code So far:
> ==============================================================
> use strict;
> use warnings;
> $\ = "\n";
> my $wmo = "07020719f.wmo";
> open OUT,'>', 'sub.txt' or die "cannot open 'sub.txt' $!";
> open WMO, '<',  $wmo;

my %station;

> while (my $obs = <WMO>) {
>         next unless $obs =~ m/^(K)/;
>         my @a = split(" ", $obs);

          my ($station, $other) = split / /, $obs,2;
          if (not exists $station{$station} or
               newer_than($other,$station{$station}) )
             { $station{$station}=$other; };

>
> }
> close OUT;

while (my ($k,$v)=each %station) {
  print "$k\t$v\n"; #or whatever format you want
};

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


------------------------------

Date: 13 Feb 2007 15:44:07 -0800
From: usenet@DavidFilmer.com
Subject: Re: Continue to Search file after matching a value
Message-Id: <1171410247.024175.278830@a34g2000cwb.googlegroups.com>

On Feb 13, 2:35 pm, "deadpickle" <deadpic...@gmail.com> wrote:
> 4. Next, continue to search the file. But instead of searching for any
> string beginning with K it instead searches for and string beginning
> with the first four letters of the station ID.
 ...
> 7. If no other similar IDs are found, go back to step 1.

Gah!  That's a convoluted mess! Run away, run away!

Just use a hash to keep track of the highest found value for each
identifier as you iterate over the file (once), such as:

#!/usr/bin/perl
   use strict;   use warnings;

   my %info;
   while (<DATA>) {
      my $letters = (split)[0];
      $info{$letters} = $_ if $info{$letters} lt $_;
   }
   print sort values %info;

__DATA__
KBQP 071845Z AUTO 35003KT 7SM OVC012 14/12 A3018 RMK AO2=
KBQP 071905Z AUTO 35003KT 7SM OVC012 14/12 A3018 RMK AO2=
KHLR 071856Z AUTO 19010KT 10SM CLR 22/13 A3007 RMK AO2 SLP179
KBQP 071925Z AUTO 35003KT 7SM OVC012 14/12 A3018 RMK AO2=


--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)



------------------------------

Date: Tue, 13 Feb 2007 19:38:51 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Continue to Search file after matching a value
Message-Id: <slrnet4q1b.iat.tadmc@tadmc30.august.net>

deadpickle <deadpickle@gmail.com> wrote:

> This is what I want the program to do:


Please see the Posting Guidelines that are posted here frequently.


> 1. Read in a file containing:
> KBQP 071845Z AUTO 35003KT 7SM OVC012 14/12 A3018 RMK AO2=
> KBQP 071905Z AUTO 35003KT 7SM OVC012 14/12 A3018 RMK AO2=
> KHLR 071856Z AUTO 19010KT 10SM CLR 22/13 A3007 RMK AO2 SLP179
> KBQP 071925Z AUTO 35003KT 7SM OVC012 14/12 A3018 RMK AO2=


You should use the __DATA__ token for providing file data.

If your aim is to find the "newest" one, then your sample data
should probably NOT be sorted oldest-to-newest...


> 2. Search for strings beginning with K at the beginning
> EXAMPLE:     next unless $obs =~ m/^(K)/;
> 3. When they are found load them into an array
> EXAMPLE:     my @a = split(" ", $obs);


Is it OK if you can accomplish what you want without loading
it into an array?


> 4. Next, continue to search the file. But instead of searching for any
> string beginning with K it instead searches for and string beginning
> with the first four letters of the station ID.
> EXAMPLE:     First time through finds that $a[0] = KBQP
>                       Continues through the file until it finds
> another KBQP
> 5. After it has found another station ID with the same name as shown
> in #4, it then checks the next value in BOTH arrays and compares them.
> The object is to see which string is the newest.


You have not mentioned how to interpret what is "newest", so I'll
just go with the greatest string-wise.


> 6. The newer string gets wrote to the array and the program continues
> to search for the same ID.
> 7. If no other similar IDs are found, go back to step 1.


Blech!

If there are 50 radio stations your algorithm will read the same
file 50 times?

That is just toooo wasteful.


> The flow should look something like this:


Why do you care what the flow looks like?

Shouldn't you instead care about whether or not it makes the
correct output, even if it uses a different flow?


> I hope this is clear. 


You want the lines with the greatest (newest) time for each
radio station that appears in the data.

Right?


> My problem is that I have no clue how to do this
> after step 3. Any help would be appreciated.
>
> Code So far:
>==============================================================
> use strict;
> use warnings;


Good. Very good.

Thank you.


> $\ = "\n";

> open OUT,'>', 'sub.txt' or die "cannot open 'sub.txt' $!";


Your code never makes any output, so those two lines are not
necesary to illustrate your problem.

If you choose an appropriate data structure, the algorithm gets
quite simple:

---------------------------------
#!/usr/bin/perl
use warnings;
use strict;

my %stations;
while ( <DATA> ) {
   next unless /^(K[A-Z]+)\s+(\S+)/;  # does not start with "K"

   if ( not exists $stations{$1} 
        or 
        $2 gt $stations{$1}{time}) {
      $stations{$1}{time} = $2;
      $stations{$1}{line} = $_;
   }
}

foreach my $station ( keys %stations ) {
   print $stations{$station}{line};
}


__DATA__
KBQP 071845Z AUTO 35003KT 7SM OVC012 14/12 A3018 RMK AO2=
KBQP 071905Z AUTO 35003KT 7SM OVC012 14/12 A3018 RMK AO2=
KHLR 071900Z AUTO 19010KT 10SM CLR 22/13 A3007 RMK AO2 SLP179
KBQP 071925Z AUTO 35003KT 7SM OVC012 14/12 A3018 RMK AO2=
KHLR 071856Z AUTO 19010KT 10SM CLR 22/13 A3007 RMK AO2 SLP179
---------------------------------


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Tue, 13 Feb 2007 19:43:34 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Continue to Search file after matching a value
Message-Id: <slrnet4qa6.iat.tadmc@tadmc30.august.net>

deadpickle <deadpickle@gmail.com> wrote:

> open OUT,'>', 'sub.txt' or die "cannot open 'sub.txt' $!";
> open WMO, '<',  $wmo;


You should always, yes *always*, check the return value from open().

You are already checking the 1st one, why stop when you got to the 2nd one?


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Tue, 13 Feb 2007 20:55:34 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: How to get table from some html
Message-Id: <d854t2l8aujioiln1maq09c68eaem1ngi7@4ax.com>

On Sat, 10 Feb 2007 14:06:41 GMT, dysgraphia <ldolan@bigpond.net.au>
wrote:

>Thanks for your input and suggestions which have been quite helpful.
>The code being used is in the preceding posts of this thread. This 

In which posts?

>includes my original code plus the valuable suggestions of gf. In the 
>interests of brevity I did not repeat all the code but I take your point 
>that for a new poster entering the thread it would have been better to 
>have repeated it.

Indeed! IIUC, if I want to know what your actual code looks like I
should find some preliminary version of it posted in this thread, then
look for someone else's suggestions, then reconstruct it from both.
But who can guarantee that I would do so in the same way you did?

>Thanks for the mention of Data::Dumper which I will investigate
>as an alternative to the Excel route.

Well, that is just a quick way to inspect your data structures. If you
need to import into a spreadsheet, that is a whole another story.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


------------------------------

Date: Tue, 13 Feb 2007 20:14:13 -0600
From: Rob Hoelz <hoelz@wisc.edu>
Subject: Lazy evaluation?
Message-Id: <20070213201413.4212f2dd@TheRing>

In a statement like this:

local $\ = "\n";
foreach $num (1..1000_000_000) {
	print $num;
}

or this:

local $\ = "\n";
foreach $line (<$handle>) {
	chomp $line;
	print $line;
}

does Perl use lazy evaluation?  Thanks!


------------------------------

Date: 13 Feb 2007 21:34:53 -0800
From: "mmccaws2" <mmccaws@comcast.net>
Subject: loading modules run test
Message-Id: <1171431293.589071.292690@a34g2000cwb.googlegroups.com>

I would like to find out where the files that test a module when
installed are stored.

I was in my Perl class installing perl modules while trying to pay
attention to the lecture.  Well, my mac needed some additional
modules, which I allowed it to pursue the others and install them.  As
it was installing each you could see the command line streaming away
with all the tests being performed on each package.
What happens to those test files for a module?  I'd like to learn from
them.

Also while I wasn't paying too much attention to which modules I was
saying yes to THE NEXT THING I REALIZED WAS THE LAPTOP WAS TALKING TO
ME  I'd like to find that test.

is there a way to find out which module was installed when?

Thanks
Mike



------------------------------

Date: 13 Feb 2007 22:53:34 -0800
From: "attn.steven.kuo@gmail.com" <attn.steven.kuo@gmail.com>
Subject: Re: loading modules run test
Message-Id: <1171436014.356539.37480@m58g2000cwm.googlegroups.com>

On Feb 13, 9:34 pm, "mmccaws2" <mmcc...@comcast.net> wrote:
> I would like to find out where the files that test a module when
> installed are stored.

Typically modules from CPAN store tests under the "t"
subdirectory.  It may be helpful for you to look at
the "MANIFEST" of a few modules.  For example:

    http://search.cpan.org/~mschwern/Test-Simple-0.67/MANIFEST

lists

    t/00signature.t
    t/00test_harness_check.t
    etc.

as tests.

If you used the 'cpan' utility to install modules,
then the files you downloaded should be found under
your $HOME/.cpan/build directory.




>
> I was in my Perl class installing perl modules while trying to pay
> attention to the lecture.  Well, my mac needed some additional
> modules, which I allowed it to pursue the others and install them.  As
> it was installing each you could see the command line streaming away
> with all the tests being performed on each package.
> What happens to those test files for a module?  I'd like to learn from
> them.


Nothing happens to those files (unless the 'cpan' utility
decides to reclaim some disk space by deleting older
files).



> Also while I wasn't paying too much attention to which modules I was
> saying yes to THE NEXT THING I REALIZED WAS THE LAPTOP WAS TALKING TO
> ME  I'd like to find that test.


The after-effect from a college frat party?
Either that, or you installed something like
Mac::Carbon that has this test:

http://search.cpan.org/src/CNANDOR/Mac-Carbon-0.77/Speech/t/Speech.t


> is there a way to find out which module was installed when?


Try

$ perldoc perllocal


--
Hope this helps,
Steven



------------------------------

Date: 13 Feb 2007 23:03:30 -0800
From: "mmccaws2" <mmccaws@comcast.net>
Subject: Re: loading modules run test
Message-Id: <1171436610.420378.9210@j27g2000cwj.googlegroups.com>

On Feb 13, 10:53 pm, "attn.steven....@gmail.com"
<attn.steven....@gmail.com> wrote:
> On Feb 13, 9:34 pm, "mmccaws2" <mmcc...@comcast.net> wrote:
>
> > I would like to find out where the files that test a module when
> > installed are stored.
>
> Typically modules from CPAN store tests under the "t"
> subdirectory.  It may be helpful for you to look at
> the "MANIFEST" of a few modules.  For example:
>
>    http://search.cpan.org/~mschwern/Test-Simple-0.67/MANIFEST
>
> lists
>
>     t/00signature.t
>     t/00test_harness_check.t
>     etc.
>
> as tests.
>
> If you used the 'cpan' utility to install modules,
> then the files you downloaded should be found under
> your $HOME/.cpan/build directory.
>
>
>
> > I was in my Perl class installing perl modules while trying to pay
> > attention to the lecture.  Well, my mac needed some additional
> > modules, which I allowed it to pursue the others and install them.  As
> > it was installing each you could see the command line streaming away
> > with all the tests being performed on each package.
> > What happens to those test files for a module?  I'd like to learn from
> > them.
>
> Nothing happens to those files (unless the 'cpan' utility
> decides to reclaim some disk space by deleting older
> files).
>
> > Also while I wasn't paying too much attention to which modules I was
> > saying yes to THE NEXT THING I REALIZED WAS THE LAPTOP WAS TALKING TO
> > ME  I'd like to find that test.
>
> The after-effect from a college frat party?
> Either that, or you installed something like
> Mac::Carbon that has this test:
>
> http://search.cpan.org/src/CNANDOR/Mac-Carbon-0.77/Speech/t/Speech.t
>
> > is there a way to find out which module was installed when?
>
> Try
>
> $ perldoc perllocal
>
> --
> Hope this helps,
> Steven

I'll check it out



------------------------------

Date: Tue, 13 Feb 2007 13:38:49 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: read from STDIN
Message-Id: <RJqdnZDPUc1ysk_YnZ2dnUVZ_tyinZ2d@comcast.com>

Joe Smith wrote:
> Petr Vileta wrote:
> 
>> I forgot to mention purpose of my code :-)
>> I try to write script for uploading files with upload progressbar.
> 
> First make sure you have the ability to code a progressbar that will
> display properly in a browser.  You'll find it awkward in plain HTML.

What I did not mention is that using CSS and/or JavaScript would probably
work better than plain HTML.  This was just announced 11-Feb-2007:

http://search.cpan.org/~isaac/Apache-UploadMeter-0.9913/
http://search.cpan.org/~isaac/Apache-UploadMeter-0.9913/lib/Apache/UploadMeter.pm

	-Joe


------------------------------

Date: 13 Feb 2007 11:39:54 -0800
From: "gf" <greg.ferguson@icrossing.com>
Subject: Re: set "From" header
Message-Id: <1171395594.935164.54140@p10g2000cwp.googlegroups.com>

On Feb 13, 11:14 am, "Larry" <larry.grant...@gmail.com> wrote:
> Forgive me if this is the wrong group, but I already posted this on
> the "sendmail" group and never got any response.

That would be because Majordomo is not sendmail. It relies on it, but
that would be the wrong group.

>
> I have an "announcements" type mail list set up in majordomo.  I
> configured the list with a "restrict_post" setting, which points to a
> file of email addresses which are authorized to send mail to the
> list.  (In case it matters, this file of "authorized senders" is small
> and seldom changes.)
>
> The list is basically working, except that when an authorized sender
> sends a mail to the list, the "From" header shows the real address of
> the sender.  I would rather the "From" header be a generic "list
> owner" address, no matter who actually sends the mail.  How can I do
> this?

For general info on Majordomo...
http://www.greatcircle.com/majordomo/
http://www.greatcircle.com/majordomo/majordomo-faq.html





------------------------------

Date: 13 Feb 2007 11:22:37 -0800
From: "A" <ad_101@yahoo.com>
Subject: waitpid woes on Solaris, Perl 5.8.8
Message-Id: <1171394557.116683.4060@p10g2000cwp.googlegroups.com>

I am getting intermittent unexpected result from waitpid on Solaris 9
running Perl 5.8.8.

Here is the scenario (the bare bones code is below).

Program_A, written in Perl, is invoked about a million times every
day. Most of the times, it invokes (using fork-exec) Program_B which
is written in C++. Program_A uses waitpid to get the exit code of
Program_B.
It works fine most of the times, but about a few dozen times every
day, the waitpid apparently fails and when it fails, I get

    $? is -1
    $! is "No child processes"

In all of the cases I have investigated, the child process, Program_B,
started and completed gracefully with "exit(0)" and of course, the pid-
s match from the trace log of both processes.

The output, from the code below, in such case is

    Child pid=5196, exitCode=0xffffffff (No child processes)

Program_A itself is transient and short lived, and, depending on its
input, executes Program_B at most once.

What am I doing wrong?
How to detect and correct this?

Thanks for your help.

# ------------------------------------------- begin code
-------------------------------------------------
#!/usr/local/bin/perl

# program_A

my $cpid;
my $ec = undef;
my $em = undef;

sub getChildStatus
{
  my $tc = undef;
  my $tm = undef;
  my $r  = undef;

  while ( 1 ) {
    $r = waitpid($cpid, 0);
    $tc = $?;
    $em  = $!;
    last  if ( -1 == $r || $r == $cpid );
    print STDERR "waitpid($cpid, 0) returned $r ( $? )\n";
  }
  if ( $cpid == $r ) {
    $ec = $tc;
    $em  = $tm;
  }
}

sub sigCLDhandler
{
  my $sig = shift;
  print STDERR "caught SIG $sig\n";
  getChildStatus;
}


sub runIt
{
  my $oldSigCld  = $SIG{CLD};
  local $SIG{CLD}  = \&sigChldHandler;

  $cpid = fork;
  if ( ! defined $cpid ) { print STDERR "fork failed [ $! ]\n";
return; }

  if ( 0 == $cpid ) {
    print STDERR "child pid $$ starting\n";

    exec program_B, .. .. ..;

    print STDERR "child pid $$: exec failed [$!], exiting with -1\n";
    exit(-1);
  } # 0 == $cpid   i.e. the child

  getChildStatus;            # only the parent reaches here
  $SIG{CLD}  = $oldSigCld ;
} # runIt

#
# main
#
runIt;
if ( $ec ) {
  printf STDERR "Child pid=$cpid exitcode=%#08x msg=(%s)\n", $ec, $em;
}

# ------------------------------------------- end code
-------------------------------------------------



------------------------------

Date: 13 Feb 2007 20:44:21 GMT
From: xhoster@gmail.com
Subject: Re: waitpid woes on Solaris, Perl 5.8.8
Message-Id: <20070213154515.959$gh@newsreader.com>

"A" <ad_101@yahoo.com> wrote:
> I am getting intermittent unexpected result from waitpid on Solaris 9
> running Perl 5.8.8.
>
> Here is the scenario (the bare bones code is below).
>
> Program_A, written in Perl, is invoked about a million times every
> day. Most of the times, it invokes (using fork-exec) Program_B which
> is written in C++. Program_A uses waitpid to get the exit code of
> Program_B.
> It works fine most of the times, but about a few dozen times every
> day, the waitpid apparently fails and when it fails, I get
>
>     $? is -1
>     $! is "No child processes"
>
> In all of the cases I have investigated, the child process, Program_B,
> started and completed gracefully with "exit(0)" and of course, the pid-
> s match from the trace log of both processes.
>
> The output, from the code below, in such case is
>
>     Child pid=5196, exitCode=0xffffffff (No child processes)
>
> Program_A itself is transient and short lived, and, depending on its
> input, executes Program_B at most once.
>
> What am I doing wrong?

You are mucking with $SIG{CLD} when, as far as I can tell, you have
no need to.  getChildStatus (and the waitpid in it) can get called twice,
once from the sig handler and once from the runIt.  If it does get called
twice, the second time that child no longer exists, as it was already
waited on. Remove the $SIG{CLD} stuff.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


------------------------------

Date: Wed, 14 Feb 2007 00:20:59 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: works now ! was: bypass shell - pipe into child pid and receive otput
Message-Id: <eqtkn2.ek.1@news.isolution.nl>

Mirco Wahab schreef:

>   my $pdf; do { local $/; $pdf = <$chld_out> };

No need for the "do" there, 


   my $pdf; {local $/; $pdf = <$chld_out>};


is sufficient.

-- 
Affijn, Ruud

"Gewoon is een tijger."


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 135
**************************************


home help back first fref pref prev next nref lref last post