Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^4: Please Explain the Parallel::ForkManager Idiom my $pid = $pm->start and next;

by Jim (Curate)
on Feb 04, 2014 at 17:10 UTC ( [id://1073445]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Please Explain the Parallel::ForkManager Idiom my $pid = $pm->start and next;
in thread Please Explain the Parallel::ForkManager Idiom my $pid = $pm->start and next;

Yep. That's the script I'm running and studying, and the one I mentioned is utterly confounding me.

Jim

  • Comment on Re^4: Please Explain the Parallel::ForkManager Idiom my $pid = $pm->start and next;

Replies are listed 'Best First'.
Re^5: Please Explain the Parallel::ForkManager Idiom my $pid = $pm->start and next;
by karlgoethebier (Abbot) on Feb 04, 2014 at 18:24 UTC

    I wonder why you are struggling so much with this issue - yet another mental block?

    Please take a look at Fork-exec. And perhaps try to build an application based on the template mentioned that does something "useful" and watch/study your process table using ps and/or top.

    And imho Network Programming with Perl by Lincoln_Stein has still a nice and gentle introduction to fork, exec, daemonizing a.s.o.

    Best regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

      "Yet another" mental block? Yes, indeed. ☹

      As evidence of my earnestness and seriousness, here's a demo Perl script my friend wrote and shared with me last weekend. I refactored it into subroutines as an exercise to help me understand how forking works, which I sort of thought I did until I started toying with Parallel::ForkManager afterwards. Please rip the script to shreds if you think it will help me learn.

      Thank you for the references to the helpful resources.

      Jim

        Please rip the script to shreds

        This subroutine is pointless.

        You are invoking an external program via system in order to sleep, but you are adding a first argument of 1 to that call to system, which means the external program is run asynchronously and the subroutine returns immediately:

        sub take_nap { my $nap_duration = int rand $MAXIMUM_NAP_TIME; return system 1, "sleep $nap_duration"; }

        Why, when you want to create a delay, are you calling it asynchronously?

        But, more to the point, why are you calling an external program in order to sleep, when perl has a built-in sleep?

        (You are aware that using fork on Windows means you're actually not forking a process but spawning a thread don't you?)


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1073445]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-25 23:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found