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

Re: Re: need help on wait();

by Ras (Acolyte)
on Mar 01, 2002 at 15:04 UTC ( [id://148579]=note: print w/replies, xml ) Need Help??


in reply to Re: need help on wait();
in thread need help on wait();

This is what i'm basically doning and it's
not working. What am i doing wrong?

system("sleep 2 &");
system("sleep 5 &");
system("sleep 20 &");
system("sleep 25 &");
system("sleep 30 &");
system("sleep 35 &");

while (wait() != -1) {}

Replies are listed 'Best First'.
(tye)Re: need help on wait();
by tye (Sage) on Mar 01, 2002 at 17:28 UTC

    system() already wait()s for the child process. To get around this you are spawning a shell and telling the shell to spawn a child and not wait for it. So system() waits for the shell to finish and you are left with a grandchild process which gets adopted by "init" (PID 1) when its parent exits and you have zero children.

    If you want to have "sleep 10" be a child that you can wait for, then you'll have to use fork (on platforms that have fork) or:     system(1,"sleep 10"); (on platforms that support that) or something even more platform-specific like use Win32::Process.

            - tye (but my friends call me "Tye")

Log In?
Username:
Password:

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

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

    No recent polls found