Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Running a process in the background

by tstock (Curate)
on Nov 23, 2004 at 22:04 UTC ( #409997=note: print w/ replies, xml ) Need Help??


in reply to Running a process in the background

You will need to fork a child process, so while that one is doing the "background" work, the parent can keep going.

If you have several background processes to run at the same time, Parallel::ForkManager is good.

Tiago


Comment on Re: Running a process in the background
Re^2: Running a process in the background
by Anonymous Monk on Nov 23, 2004 at 22:07 UTC
    Hello,

    Thanks for your response. Can you give me an example of how to use fork to start a function in a perl module in the background?

    Thank you.

      if (my $pid = fork) { # parent ($pid is process id of child) parent_function(); } else { # child child_function(); exit; }
      Feel free to read perldoc -f fork, and look at some examples online. This is not really advanced perl, but it requires some attention.
        From personal experience, the exit is key. Let's just say that I'm glad that I had my own Sun workstation when I started experimenting with fork...*cough*fork bomb*cough*

        thor

        Feel the white light, the light within
        Be your own disciple, fan the sparks of will
        For all of us waiting, your kingdom will come

        Hello, Remember to check for a fork error after forking:
        if (my $pid = fork) { ## Parent } elsif ($pid == 0) { ## Child } else { ## Error, $pid is undefined }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2014-11-23 22:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (134 votes), past polls