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")