Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

How can I run a portion of code (like fork() does) w/o creating its own process?

by david28 (Initiate)
on Oct 23, 2000 at 23:51 UTC ( #38005=perlquestion: print w/replies, xml ) Need Help??

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

I need to run a block of code, a subroutine, but creating a pid for each is overkill. Its likely to run at least 80 times a minute, for days on end.

Originally posted as a Categorized Question.

  • Comment on How can I run a portion of code (like fork() does) w/o creating its own process?

Replies are listed 'Best First'.
Re: How can I run a portion of code (like fork() does) w/o creating its own process?
by AgentM (Curate) on Oct 24, 2000 at 06:30 UTC
    You might try experimenting with threads as they are "experimental". use Threads; but you'd better read this post by me. Modern OSs provide threads but Perl has a deficiency that basically kills any thread use.
Re: How can I run a portion of code (like fork() does) w/o creating its own process?
by nerdie (Initiate) on Jun 14, 2002 at 04:30 UTC
    You might want to try redesigning your code to use POE (Perl Object Environment). This lets you write multitasking programs often without fork() overhead. You can design your 'child' subroutines as new Sessions, which is synonymous to a process, but without using the underlying fork() system call.
Re: How can I run a portion of code (like fork() does) w/o creating its own process?
by merlyn (Sage) on Oct 23, 2000 at 23:57 UTC
    You should prefork then, like Apache does.
Re: How can I run a portion of code (like fork() does) w/o creating its own process?
by entropy (Sexton) on Jun 09, 2001 at 01:53 UTC
    If your 'child' subroutines don't need to run in the background, just do an eval{}. If you need the main code to run at the same time as the children, but two children won't run at once, then you can do one fork and re-use the child process for each task you have to do.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2021-04-19 10:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?