Operating System - HP-UX
1833709 Members
2499 Online
110063 Solutions
New Discussion

PERL & UNIX : critical race?

 
SOLVED
Go to solution
Enrico Venturi
Super Advisor

PERL & UNIX : critical race?

Hello colleagues;
please see the following branch of a PERL program:
$pid_open3 = open3($in, $out, "", "/usr/contrib/bin/gzip -c $currFile");

my $hnd = RemoteWriteFromArray($host, "${currRemoteFile}.gz", $user, $group, $mode, undef, $system, $instance, "NOBUFFER");

while (<$out>) {
print $hnd $_;
}

The expected behaviour is:
run a gzip by the open3
recevives the output of gzip by $out
write to the remote socket the output of gzip

Unfortunately sometimes it doesn't work: the gzip continues producing output but nothing is sento to the remote socket

Maybe the print fails because the $hnd isn't a valida handler anymore or something else?
maybe the gzip output isn't catched anymore by the script?

thanks
Enrico
4 REPLIES 4
Elmar P. Kolkman
Honored Contributor

Re: PERL & UNIX : critical race?

Enrico, I would suggest to start testing result codes from the routines ('or die "...") to begin with. Make sure te RemoteWriteFromArray results in a valid socket. And while you're at it, also check the open3 call. You might even check the print command.

Every problem has at least one solution. Only some solutions are harder to find.
Enrico Venturi
Super Advisor

Re: PERL & UNIX : critical race?

The fact is that the remote write is started but it's stopped after a while ...
For instance for a file of 69478 bytes only 44563 are written .. this is almost systematic when the script runs free; it doesn't happen when I run the PERL debugger :-(
Ralph Grothe
Honored Contributor
Solution

Re: PERL & UNIX : critical race?

Hi Enrico,

could it be that your code fell victim to Unix buffering of the gzip command?

Have a look at the POD of IPC::Open3 (i.e. perldoc IPC::Open3) where this issue is mentioned.

In the perlipc POD (perldoc perlipc) position your pager's cursor to "/Unix buffering".
There you will find a hack that uses pseudo tty to overcome this.
Madness, thy name is system administration
Enrico Venturi
Super Advisor

Re: PERL & UNIX : critical race?

Hello,
I tried to change my code but now I get this error ....
my($out) = gensym();
$out = open_proc('/usr/contrib/bin/gzip -c $currFile');


DB<7> n
Remotizer doesn't contain an __DATA__ token at /alcatel/Kernel/lib/lib_perl/Remotizer.pm line 1440
Carp::croak('Remotizer doesn\'t contain an __DATA__ token') called at /usr/local/lib/perl5/5.00503/SelfLoader.pm line 45
SelfLoader::_load_stubs('SelfLoader', undef) called at /usr/local/lib/perl5/5.00503/SelfLoader.pm line 19
SelfLoader::AUTOLOAD('/usr/contrib/bin/gzip -c $currFile') called at /alcatel/Kernel/lib/lib_perl/Remotizer.pm line 1440
Remotizer::RemoteCopy('/tmp/y', 'h3grm2:/tmp/db.sav', 'snml', 'dba', 0777, 'compress') called at ./xxx line 83
Debugged program terminated. Use q to quit or R to restart,
use O inhibit_exit to avoid stopping after program termination,
h q, h R or h O to get additional info.
DB<7>