Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Fork Information

by blacksmith (Hermit)
on Jun 14, 2001 at 20:05 UTC ( [id://88467]=perlquestion: print w/replies, xml ) Need Help??

blacksmith has asked for the wisdom of the Perl Monks concerning the following question:

I am seeing a lot of discussion about "fork". I am new to Perl (and loving every minute of this trek of learning) and was thinking that a very thorough tutorial where an aspiring Perl Hacker like myself could learn the full ins and outs of this process would make an excellent addition to this site. Not to mention that my first "real" Perl program is being adopted to help run a document managment system here at my job, and I feel that fork could make the program more effecient. Thanks for this site and the work that goes into it. Blacksmith.

Replies are listed 'Best First'.
Re: Fork Information
by koolade (Pilgrim) on Jun 14, 2001 at 22:42 UTC

    Maybe not as thorough as you'd like, but I think the first place you should lok (if you haven't already) is the perl docs for fork. It also links to perlipc which also has some good related information.

      koolade:

      I often find the explanations for fork to be usually a little self-imporant (as they were for me when I got started).

      Here's teh babble-free version of fork as it was originally explained to me

      Your program runs instructions sequentially, like a car driving by itself down the road, where each traffic event (stop light, intersection, traffic sigh) is the equivalent of a code instruction (such as print "hello,world.\n") in the source code.

      When you fork, you are cloning your car and giving the clone its own identity, and telling each car about the existance of the other car.

      What happens now is that each car starts going down the same road (the same code, starting from the fork command) in parallel, at first, until the second car finds an instruction telling it to do something based on its identity as the second car (the child)

      And this goes on until something tells one of the cars (the parent or the child) to dissapear.

      Now, something to consider is that this second car takes a lot of energy to generate (and a fork ahs a fair bit of overhead at first).

      I hope you dont find this explanation too pedantic.
      For a real explanation, refer to the doc as advised by the others.

      --Hackmare

        Not pedantic at all (unless you meant the good connotation of pedantic) I finally understand what fork is all about.
Re: Fork Information
by earthboundmisfit (Chaplain) on Jun 15, 2001 at 16:24 UTC
    Be especially wary of fork if your script is intended to run on multiple platforms. The Camel book recommends Win32::Process instead for Microsoft based systems. As of Perl 5.6, there is an emulator, but performance is an issue.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-04-18 07:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found