SPUG: Re: Forked Children talking back to the parent?

John Cokos jcokos at ccs.net
Wed Jan 17 12:43:34 CST 2001


I suppose I should further qualify something about this ....

The targeted users for this are webmasters.  We are a CGI
Shop, so about the only thing we know going in the door
is that it'll likely be a Unix machine, with Perl 5.  Generally
ISPs that host websites, and allow CGI's wont' allow pipes,
IO:: ... or Shared memory usage.  Even fork() is only available to
us in about 60% of the cases.

So this thing really has to be "dumbed down"

If there's not a built in way for a child to manipulate a
variable (array or hash) directly in the parent process, then
I'll have to find another way.

I could use DB_File and tie to a disk hash, and then all the
children and parents could access the same set of data, live,
but there'd be some record locking issues to deal with.

John

========================================
  John Cokos, President / CEO: iWeb Inc.
  http://www.iwebsys.com
  jcokos at ccs.net
========================================

----- Original Message -----
From: "John Cokos" <jcokos at ccs.net>
To: <spug-list at pm.org>
Sent: Wednesday, January 17, 2001 7:43 AM
Subject: SPUG: Forked Children talking back to the parent?


> Working on a long running perl script, that I think would be better suited to using fork() than running on it's own.
>
> Basically, the pseudocode for it is something like this:
>
>
>
> code:------------------------------------------------------------------------------my @to_do_list
>
> push @to_do_list, $something;
>
> foreach my $item ( @to_do_list ) {
>
>     .. do some work.
>     if ( I find something else to do)  {
>        push @to_do_list, $this_new_thing;
>     }
>
> }
> ------------------------------------------------------------------------------
>
>
> So, you can see that it's an array that can be added to in mid-stream, and continually grows. Depending on the amount of things
> "found to do" in the inside loop, it can take hours and hours to run, as that array grows larger.
>
> What I'm wanting to do, is fork off 10 child processes, and have each of them doing the same loop, each aware of the master
array's
> contents, and each able to push things onto it, so that the other children, when they're in the loop see the new todo items...
>
> Can the children intercommunicate?
>
> If not, can they at least return a value back to the parent?
> In this case, we could have it fork 10, give them a task, get back the new todo items found, and die. Then, fork 10 new kids, etc
> ....
>
> Thanks, John
> ========================================
>   John Cokos, President / CEO: iWeb Inc.
>   http://www.iwebsys.com
>   jcokos at ccs.net
> ========================================
>
>
>
>  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>      POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
>       Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
>   Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
>  For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
>   Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
>
>
>


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/





More information about the spug-list mailing list