Home > Archive > Unix Programming > November 2005 > while (wait(&status) != pid) and waitpid (pid, &status, 0)
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
while (wait(&status) != pid) and waitpid (pid, &status, 0)
|
|
|
|
| Paul Pluzhnikov 2005-11-26, 9:56 pm |
| "Alex Vinokur" <alexvn@x-privat.org> writes:
> Are 'while (wait(&status) != pid)' and 'waitpid (pid, &status, 0)' have the same behavior?
No.
The first one will collect any child processes that have exit()ed;
the second will wait only for the specified process.
Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
| |
| Alex Vinokur 2005-11-26, 9:56 pm |
|
"Paul Pluzhnikov" <ppluzhnikov-nsp@charter.net> wrote in message news:m3d5knpcf2.fsf@somewhere.in.california.localhost...
> "Alex Vinokur" <alexvn@x-privat.org> writes:
>
>
> No.
>
> The first one will collect any child processes that have exit()ed;
> the second will wait only for the specified process.
>
[snip]
'wait(&status)' collects any child processes that have exit()ed
Also 'while (wait(&status) != pid)' ?
--
Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn
| |
| Paul Pluzhnikov 2005-11-26, 9:56 pm |
| "Alex Vinokur" <alexvn@x-privat.org> writes:
> 'wait(&status)' collects any child processes that have exit()ed
Yes. Did you have a question about it?
> Also 'while (wait(&status) != pid)' ?
Huh? What are you trying to ask?
Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
| |
| Alex Vinokur 2005-11-26, 9:56 pm |
|
"Paul Pluzhnikov" <ppluzhnikov-nsp@charter.net> wrote in message news:m38xvbpas3.fsf@somewhere.in.california.localhost...
> "Alex Vinokur" <alexvn@x-privat.org> writes:
>
>
> Yes. Did you have a question about it?
>
>
> Huh? What are you trying to ask?
>
[snip]
http://man.he.net/man2/waitpid
The wait function suspends execution of the current process until a child has exited, or ...
The waitpid function suspends execution of the current process until a child as specified by the pid argument has exited, or
....
The 'while (wait(&status) != pid)' statement suspends execution of the current process until ???
--
Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn
| |
| Alex Fraser 2005-11-26, 9:56 pm |
| "Alex Vinokur" <alexvn@x-privat.org> wrote in message
news:43888857$1_2@x-privat.org...
> Are 'while (wait(&status) != pid)' and 'waitpid (pid, &status, 0)' have
> the same behavior?
No. Ignoring errors, the wait() loop ends after the child specified by pid
terminates, and waitpid() returns after the child specified by pid
terminates. But the wait() loop may collect (and promptly throw away) the
statuses of some other children, whereas waitpid() will not.
Alex
| |
| Paul Pluzhnikov 2005-11-26, 9:56 pm |
| "Alex Vinokur" <alexvn@go.to> writes:
> The 'while (wait(&status) != pid)' statement suspends execution of the current process until ???
Until the process specified by pid has exited (assuming 'pid' is the
(positive) process id of one of current process's children).
The difference between this and 'waitpid(pid, &status, 0)' is that
the 'while()' may *also* collect exit status for *other* children
that may have exited, while waitpid() will leave all such other
children alone (and in "zombie" state).
Generally, collecting exit status of childrent you did not spawn
and do not expect is a bad idea -- there may be other code which
expects to collect *its* children later, and such code may become
unhappy when it receives ECHILD from waitpid().
Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
|
|
|
|
|