Sorry for the pun- it's late. Anyways, I'm new to using Fork(), and I dont think I'm following it too well. Here is an app that I am hammering out. The issue is that I dont see it forking. Here is the code.
#!/usr/bin/perl -w strict use strict; use DBI; my $dbh = DBI->connect('DBI:mysql:noc', 'root', '') or die "Couldn't o +pen database: $DBI::errstr; stopped"; while (1) { my $sth = $dbh->prepare("select assetid,ip,snmpname from assets") or d +ie "Couldn't prepare statement: $DBI::errstr; stopped"; $sth->execute() or die "Couldnt execute statement: $DBI::errsrt; stopp +ed"; my @a; while ( my ($aid, $aip, $asnmp) = $sth->fetchrow_array() ) { my @a = ($aid, $aip, $asnmp); forkin($aid, $aip, $asnmp); } sleep(5); print "repeating\n"; } sub forkin { my $aid = shift; my $aip = shift; my $asnmp = shift; my @ret; my $pid=fork(); die "Cannot fork: $!" if (! defined $pid); if (! $pid) { my @ret = ping_remote($aip,$asnmp); commitDB($aip,$aid,$asnmp,@ret); exit 0; } waitpid($pid,0); } sub commitDB { my $ip = shift; my $assetid = shift; my $snmpname = shift; my @ret = @_; if (@ret) { my $sth2 = $dbh->prepare("insert into history set assetid='$asse +tid', trafficload='$ret[1]'") or die "Couldn't prepare statement: $DB +I::errstr; stopped"; $sth2->execute() or die "Couldnt execute statement: $DBI::errsrt +; stopped"; $sth2 = $dbh->prepare("update assets set firmware='$ret[2]', upt +ime='$ret[1]', status='u', trafficload='$ret[0]' where assetid='$asse +tid'") or die "Couldn't prepare statement: $DBI:: errstr; stopped"; $sth2->execute() or die "Couldnt execute statement: $DBI::errsrt +; stopped"; } else { my $sth2 = $dbh->prepare("update assets set status='d' where ass +etid='$assetid'") or die "Couldn't prepare statement: $DBI::errstr; s +topped"; $sth2->execute() or die "Couldnt execute statement: $DBI::errsrt +; stopped"; } } sub ping_remote { my $ip = shift; my $snmpname = shift; my @ret = undef; my @p = split(/(,)/,`ping -c 1 $ip | grep "0% loss"`); if ($p[4] eq " 0% loss") { my $a=`/etc/poller/snmptraffic.php "$ip" "$snmpname"`; my $u=`/etc/poller/snmpuptime.php "$ip" "$snmpname"`; my $f=`/etc/poller/snmpfirmware.php "$ip" "$snmpname"`; @ret = ($a,$u,$f); } return @ret; }
You may be wondering what the php files are for- well, I'm going to play with SNMP next with Perl :P To summarize, when executed, I want the program to pull data from a database and fork subprocesses that will do the polling and then store their values into a database. I already have this functionality in another perl app, but it only does it sequentially- I dont want that. Imagine polling 16,000 devices, taking 1 second per device. That's about 4.4 hours until getting back to the first device. Someone mind steering me into the right direction again? Thanks all!

In reply to Forking Issues by satanklawz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.