0

I have also a problem with an "Out of Memory" by running a simple pearl script. In xubuntu 16.04 it works without errors. With 18.04 it doesn't work any more.

I have to send different HL7-messages from a file to a receipient. After sending the first one and before it's getting the result "Antwort" the error occurs.

#!/usr/bin/perl
use IO::Socket;
use POSIX qw(strftime);

$count=0;
$global_time=0;
$again="true" ;
$a=chr(11);
$y=chr(28);
$z=chr(13);

if ($ARGV[2] eq "")
{
  print "Usage: caller.pl <Zielrechner> <Socket> <Datei>\n";
}
else
{

  open(LOG, ">> log.txt") || die "Fehler!\n";
  print LOG "New Start...\n";

  $sock = IO::Socket::INET->new (
       PeerAddr => $ARGV[0],
       PeerPort => $ARGV[1],
       Proto => 'tcp',
  ) or
  die "Could not create socket: $!\n" unless $sock;
  $sock->autoflush(1);

  open(INPUT, "<".$ARGV[2]) || die "Datei nicht gefunden!\n";

  while(<INPUT>)
  {
    $log=$_;
    $log=~s/$z/\^M/g;
    @zeile=split(/\n/,$_);
    $zeile[0]=~s/\n*$//;
    $zeile[0]=~s/\$z/$z/g;

    $start=time;
    print $sock $a ,$zeile[0], $y, $z;

    print "Anfrage: ".strftime("%Y%m%d,%H:%M:%S", localtime)."\n";
    print LOG "Anfrage: ".strftime("%Y%m%d,%H:%M:%S", localtime)."\n";
    print LOG "Angefragt: $log\n";
    print "Angefragt: $log\n";

    #    sleep 10;

    while ($again eq "true")
    {
      $nread=sysread($sock, $ant, []);

      if ($nread <= 0)
      {
        print "sysread returned nothing...\n";
        print LOG "sysread returned nothing...\n";
        $again="false";
        close($sock);
        undef $sock;

        sleep 1;
        $sock = IO::Socket::INET->new (
                     PeerAddr => $ARGV[0],
                     PeerPort => $ARGV[1],
                     Proto => 'tcp',
                ) or
        die "Could not create socket: $!\n" unless $sock;
        $sock->autoflush(1);
      }

      $ant=$merk.$ant;

      if ($ant =~ /^$a.*$y$z$/)
      {
        $count = $count + 1;
        $ant =~ s/$z/\$z/g;
        $jetzt=time;
        $erg=$jetzt-$start;
        $global_time = $global_time + $erg;
        $average = $global_time / $count;
        print LOG "Antwort: $jetzt $ant\nDauer: $erg s  Avg: $average s\n";
        print "Antwort: $jetzt $ant\nDauer: $erg s  Avg: $average s\n";
        print LOG "-------\n";
        $again="false";
      }
      else
      {
        $merk=$ant;
      }
    }

    $again="true";
    $merk="";
    $ant="";
    $start="";
    $jetzt="";
    $erg="";
  }

  close(LOG);
  close(INPUT);
}

Does anybody have an idea?? Is there a property I have to change?

Thanks for your help

  • 1
    How much RAM do you have? How much SWAP? – waltinator Mar 2 at 14:07
  • My RAM: 16 GB total, 5,6GB free, 4GB used, 6GB Cache My Swap: 2GB total, 2GB free, 11GB verf. – Johannes Schricker Mar 8 at 7:27

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.