Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Fork/Child Question

by beable (Friar)
on Jul 28, 2004 at 01:39 UTC ( [id://377900]=note: print w/replies, xml ) Need Help??


in reply to Fork/Child Question

Here's how you can do it using threads, assuming that your Perl has threading built in. (run perl -V to check if you can use threads (look for usethreads=define)).

#!/usr/bin/perl use strict; use warnings; use threads; foreach (0..100) { # create a thread to call the "run_system" subroutine # to run "ls -la" on the OS my $thread = threads->create("run_system", "ls -la"); $thread->detach; } sub run_system { my $cmd = shift; system($cmd); } __END__

Replies are listed 'Best First'.
Re^2: Fork/Child Question
by BrowserUk (Patriarch) on Jul 28, 2004 at 03:19 UTC

    Or as a one-liner :)

    perl -Mthreads=async -le"async{ system 'dir'; } for 1 .. 100"

    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    "Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - tachyon

Log In?
Username:
Password:

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

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

    No recent polls found