multithreading - array missing elements with a subroutine thread -


a simple code either run in thread or without thread. when run in thread processing doesn't process elements in array. when run without threading processes elements.

#!/usr/bin/perl -w -i /opt/hypertable/0.9.7.3/lib/perl -i /opt/hypertable/0.9.7.3/lib/perl/gen-perl use strict; use io::socket; use geo::ip; use threads qw(stringify); use net::nbname; use data::dumper; use hypertable::thriftclient;  # syslog variables , constants $maxlen = 1524; $limit = 5; #for testing $sock; # start listening on udp port 514 $sock = io::socket::inet->new(localport => '514', proto => 'udp') || die("socket: $@");  $buf = ''; $count = 0; @set;  ($count = 0; $count <= $limit; $count++) {   $sock->recv($buf, $maxlen);   ($port, $ipaddr) = sockaddr_in($sock->peername);   $hn = gethostbyaddr($ipaddr, af_inet);   $buf =~ /<(\d+)>(.*?):(.*)/;   $msg = $3;   $set[$count][0] = $hn;   $set[$count][1] = $msg;   print $count." --> ".$set[$count][0]." --> ".$set[$count][1]."\n";#print original array, should print 5 elements     $thr = threads->create('logsys',@set);    #&logsys(@set); }  sub logsys {   $count = 0;   @set = @_;    print "--------------------- ".scalar (@set)." -------------------\n";    ($count=0; $count <= $limit; $count++) {     print $count." --> ".$set[$count][0]." --> ".$set[$count][1]."\n";#print passed array, should same exact 5 elements     if (open(ww,">syslog")){       print ww $count." --> ".$set[$count][0]." --> ".$set[$count][1]."\n"; close(ww);     }   } } 

o/p when run thread:

0 --> ids-01p --> 23:48 ids01 sfims: [flids][enterprise][138:4:1] sensitive_data: sensitive data - u.s. social security numbers without dashes [classification: sensitive data] [priority: 2] {tcp} 10.10.97.42:3065 -> 33.87.66.38:80 1 --> ids-01p --> 23:50 ids01 sfims: [flids][enterprise][138:4:1] sensitive_data: sensitive data - u.s. social security numbers without dashes [classification: sensitive data] [priority: 2] {tcp} 10.10.1.254:26616 -> 78.67.61.202:80 2 --> ids-01p --> 23:50 ids01 sfims: [flids][enterprise][138:4:1] sensitive_data: sensitive data - u.s. social security numbers without dashes [classification: sensitive data] [priority: 2] {tcp} 10.10.1.254:39180 -> 56.164.27.51:80 3 --> ids-01p --> 23:51 ids01 sfims: [flids][enterprise][138:4:1] sensitive_data: sensitive data - u.s. social security numbers without dashes [classification: sensitive data] [priority: 2] {tcp} 10.10.52.97:53967 -> 173.194.37.97:80 4 --> ids-01p --> 23:51 ids01 sfims: [flids][enterprise][119:15:1] http_inspect: oversize request-uri directory [classification: potentially bad traffic] [priority: 2] {tcp} 10.190.1.254:57265 -> 34.44.17.21:80 5 --> ids-01p --> 23:51 ids01 sfims: [flids][enterprise][119:15:1] http_inspect: oversize request-uri directory [classification: potentially bad traffic] [priority: 2] {tcp} 10.190.1.254:41960 -> 34.44.17.29:80 --------------------- 6 ------------------- 0 --> ids-01p --> 23:48 ids01 sfims: [flids][enterprise][138:4:1] sensitive_data: sensitive data - u.s. social security numbers without dashes [classification: sensitive data] [priority: 2] {tcp} 10.190.97.42:3065 -> 43.87.66.38:80 perl exited active threads:         1 running , unjoined         0 finished , unjoined         0 running , detached 1 --> ids-01p --> 23:50 ids01 sfims: [flids][enterprise][138:4:1] sensitive_data: sensitive data - u.s. social security numbers without dashes [classification: sensitive data] [priority: 2] {tcp} 10.190.1.254:26616 -> 43.67.61.202:80 

o/p when run without thread:

0 --> ids-01p --> 36:48 ids01 sfims: [flids][enterprise][138:4:1] sensitive_data: sensitive data - u.s. social security numbers without dashes [classification: sensitive data] [priority: 2] {tcp} 10.10.1.254:34053 -> 69.164.26.77:80 1 --> ids-01p --> 36:50 ids01 sfims: [flids][enterprise][138:4:1] sensitive_data: sensitive data - u.s. social security numbers without dashes [classification: sensitive data] [priority: 2] {tcp} 10.1.65.51:57977 -> 216.137.41.5:80 2 --> ids-01p --> 36:53 ids01 sfims: [flids][enterprise][128:4:1] ssh: protocol mismatch [classification: detection of non-standard protocol or event] [priority: 2] {tcp} 10.10.241.46:11120 -> 10.10.125.227:22 3 --> ids-01p --> 36:54 ids01 sfims: [flids][enterprise][128:4:1] ssh: protocol mismatch [classification: detection of non-standard protocol or event] [priority: 2] {tcp} 10.10.241.46:11122 -> 10.1.125.225:22 4 --> ids-01p --> 36:54 ids01 sfims: [flids][enterprise][138:4:1] sensitive_data: sensitive data - u.s. social security numbers without dashes [classification: sensitive data] [priority: 2] {tcp} 10.1.118.96:61686 -> 50.19.254.195:80 5 --> ids-01p --> 36:54 ids01 sfims: [flids][enterprise][138:4:1] sensitive_data: sensitive data - u.s. social security numbers without dashes [classification: sensitive data] [priority: 2] {tcp} 10.1.1.254:29437 -> 184.73.178.248:80 --------------------- 7 ------------------- 0 --> ids-01p --> 36:48 ids01 sfims: [flids][enterprise][138:4:1] sensitive_data: sensitive data - u.s. social security numbers without dashes [classification: sensitive data] [priority: 2] {tcp} 10.10.1.254:34053 -> 69.164.26.77:80 1 --> ids-01p --> 36:50 ids01 sfims: [flids][enterprise][138:4:1] sensitive_data: sensitive data - u.s. social security numbers without dashes [classification: sensitive data] [priority: 2] {tcp} 10.1.65.51:57977 -> 216.137.41.5:80 2 --> ids-01p --> 36:53 ids01 sfims: [flids][enterprise][128:4:1] ssh: protocol mismatch [classification: detection of non-standard protocol or event] [priority: 2] {tcp} 10.10.241.46:11120 -> 10.10.125.227:22 3 --> ids-01p --> 36:54 ids01 sfims: [flids][enterprise][128:4:1] ssh: protocol mismatch [classification: detection of non-standard protocol or event] [priority: 2] {tcp} 10.10.241.46:11122 -> 10.1.125.225:22 4 --> ids-01p --> 36:54 ids01 sfims: [flids][enterprise][138:4:1] sensitive_data: sensitive data - u.s. social security numbers without dashes [classification: sensitive data] [priority: 2] {tcp} 10.1.118.96:61686 -> 50.19.254.195:80 5 --> ids-01p --> 36:54 ids01 sfims: [flids][enterprise][138:4:1] sensitive_data: sensitive data - u.s. social security numbers without dashes [classification: sensitive data] [priority: 2] {tcp} 10.1.1.254:29437 -> 184.73.178.248:80 

you need use thread join wait thread finish job ($thr->join()), thats reason complaining unjoined threads: 1 running , unjoined


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -