FTP Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsSystem AdministrationFTP Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 9th, 2002, 11:14 PM
Gk0r Gk0r is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 36 Gk0r User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Fork()ing NET::FTP - taboo?

Hey guys,

Latly I've spent some time trying to get to know fork() a little better. It's somewhat challenging, it would seem that all the docs on the net about it are a little overly complicated, here is what I've got and if you think it's lame or bad sample, bear with me, that's one of my first attemps on fork(), I borrowed most of the code from samples here and there.

It would seem that it works just fine, untill I call on NET::FTP, I mean i tried sticking just some code pieces inside and it works, as soon as I put something in that involves objects(??), like DBI or FTP it stops working, I wonder if anybody could help me out.

Thanks in advance,


Code:
#! /usr/bin/perl

use NET::FTP;

use constant CLIENTS   => 3;
use constant DEBUG     => 1;

my @kids=();
my $pid=$$;
my $parentpid=0;

sub Forker {
    my $clients=shift;
    my $i=0;
    while ($i++ < $clients) {
        my $newpid = fork();
        if (! defined $newpid) { #hosed
            die "fork() error: $!\n";
        }
        elsif ($newpid == 0) { #child
            $parentpid = $pid;
            $pid = $$;
            @kids = (); #don't inhert the kids
            last;
        }
        else { #parent   (defined $newpid)
            push(@kids, $newpid);
        }
    }
}

sub SharedInit {

}

sub Work {

print "Connecting...\n";
if(!($f=Net::FTP->new("127.0.0.1", Port => 21, Debug => 0, Timeout => 5))) {print "FTP Conenction Failed\n"}
$f->quit;
print "<br>Connected Sucessfully.\n";

}

sub Reaper {
    while (my $kid = shift(@kids)) {
        my $reaped = waitpid($kid,0);
        unless ($reaped == $kid) {
        }
    }
}



SharedInit();

Forker(CLIENTS);

if ($parentpid) {
    Work();
}
else { #the original parent only does cleanup duty
    Reaper();
}

if ($parentpid) {exit(0);}
else {exit(0);}
die;

__END__

     use POSIX ":sys_wait_h";
     do {
         $kid = waitpid(-1,&WNOHANG);
     } until $kid == -1;

Reply With Quote
  #2  
Old October 11th, 2002, 04:42 AM
SurfMonkey SurfMonkey is offline
Bare knuckle tiger fighter
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: MK the UK
Posts: 44 SurfMonkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Could try that one on perlmonks.com, they seem to have a endless supply of arcane knowledge.

Reply With Quote
  #3  
Old November 8th, 2002, 01:25 AM
Gk0r Gk0r is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 36 Gk0r User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
I am sorry for bumping this up, however I feel that this is appropriate, is has been a while since i asked, however I found solution and if someone else have the same problem they may learn for my experience in this particular matter.

My problem was not with fork() as it turns out, rather with windows and they way activestate fork()s

Once moved to unix platform which fork() was originally designed for all my problems disappeared and everything works, allthough I dealt away with above code snippit, if you have the same problem, just kick win in the nuts and go with something things were made for

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationFTP Help > Fork()ing NET::FTP - taboo?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway