Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: System Function...script does not move until process ends.

by Joost (Canon)
on Apr 05, 2005 at 18:40 UTC ( [id://445077]=note: print w/replies, xml ) Need Help??


in reply to Re^2: System Function...script does not move until process ends.
in thread System Function...script does not move until process ends.

fork, perlipc and perlopentut have examples.

  • Comment on Re^3: System Function...script does not move until process ends.

Replies are listed 'Best First'.
Re^4: System Function...script does not move until process ends.
by curtisb (Monk) on Apr 05, 2005 at 18:52 UTC

    Ok, excuse my ingnorance on this fork issue. I have never used it before. Could someone please take a look at the code I wrote (above) and suggest something or how I should do it.

    After I start the database again, I want to be able make a connection to it using the dbi module in perl. I've done that, but I need to know more or shown the suggestion on how fork works.

    Thanks,

    Bobby

      try something like:
      use POSIX ":sys_wait_h"; sub startTheDB { (defined $pid = fork()) or die "Unable to fork!\n"; if ( !$pid ) { exec "StartTheDB" or die "Can't start the db!\n"; } else { do { $kid = waitpid(-1, WNOHANG); } until $kid > 0; } }
      Note that you'll want to test the db from the parent after you return from the sub.


      Updated: It still waits for the child - as pointed out by frodo72

      Just a note that the scary looking stuff (e.g. the waitpid) is explained in the docs mentioned throughout this node and here
      --------------
      "But what of all those sweet words you spoke in private?"
      "Oh that's just what we call pillow talk, baby, that's all."
        Sorry, I don't see the point.

        If my synapses are not too cluttered due to hanger (which could be, it's dinner time here :), your sub keeps the parent waiting for child's death, which is exactly what system does. But while system does this "efficiently", putting the parent process to sleep (I hope this happens in Windows as well, can't swear on it >;), this function does a quite active wait, given the WNOHANG option. So, it seems to me that not only this does not solve the problem, but increases CPU load!

        What am I missing (apart a good dinner)?

        Flavio (perl -e "print(scalar(reverse('ti.xittelop@oivalf')))")

        Don't fool yourself.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-24 02:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found