Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Confused by fork examples

by reasonablekeith (Deacon)
on Dec 18, 2005 at 11:28 UTC ( [id://517589]=note: print w/replies, xml ) Need Help??


in reply to Confused by fork examples

You don't need to start new process with eval, when you run 'fork' you will already have two exact copies of you program running.

fork creates this dupicate in a child process of the one running the original perl script. The way you tell them apart is by checking the id returned from fork. If the id is 0, you are in the child process. If the id is non-zero, you are in the parent. That non-zero id is the id of the spawned child process.

so, after running fork, check the id and condition your code appropriately for the child or the parent

---
my name's not Keith, and I'm not reasonable.

Log In?
Username:
Password:

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

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

    No recent polls found