caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* AW: [Caml-list] Unix.waitpid
@ 2005-06-30 12:31 Bauer, Christoph
  2005-06-30 12:44 ` Oliver Bandel
  0 siblings, 1 reply; 3+ messages in thread
From: Bauer, Christoph @ 2005-06-30 12:31 UTC (permalink / raw)
  To: caml-list

Sorry,

> let wait ?(delay_time = 0.01) pid idle x =
>   let rec wait' () =
>     idle x;
>     delay delay_time;
>     let pid = try fst (Unix.waitpid [Unix.WNOHANG] pid) with 
> _  -> 1 in
>       if pid <> 0 then wait' ()
>   in wait' ()
this code is wrong, my original code was:

let rec wait' () =
      idle x;
      delay delay_time;
     let wpid = try fst( Unix.waitpid [Unix.WNOHANG] pid) with _ -> pid in
       if pid <> wpid then wait' ()
    in wait' ()

Christoph Bauer


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] Unix.waitpid
  2005-06-30 12:31 AW: [Caml-list] Unix.waitpid Bauer, Christoph
@ 2005-06-30 12:44 ` Oliver Bandel
  0 siblings, 0 replies; 3+ messages in thread
From: Oliver Bandel @ 2005-06-30 12:44 UTC (permalink / raw)
  To: caml-list

On Thu, Jun 30, 2005 at 02:31:06PM +0200, Bauer, Christoph wrote:
> Sorry,
> 
> > let wait ?(delay_time = 0.01) pid idle x =
> >   let rec wait' () =
> >     idle x;
> >     delay delay_time;
> >     let pid = try fst (Unix.waitpid [Unix.WNOHANG] pid) with 
> > _  -> 1 in
> >       if pid <> 0 then wait' ()
> >   in wait' ()
> this code is wrong, my original code was:
> 
> let rec wait' () =
>       idle x;
>       delay delay_time;
>      let wpid = try fst( Unix.waitpid [Unix.WNOHANG] pid) with _ -> pid in
>        if pid <> wpid then wait' ()
>     in wait' ()


Well, using the corresponding C-API-function,
you should better rename your arguments:

  wpid is the pid you wait for (the argument to Unix.waitpid)  and
   pid is the value you get from that function:


===== from the wait(2)/waitpid(2)-manpage =============
     pid_t
     waitpid(pid_t wpid, int *status, int options);
=======================================================


BTW: where do you set the "pid" initially?

And: if waitpid returns with a pid, then you can't wait on this
pid/process again. So, if you wait for one pid and get a different
pid as result of the function call, then you wait again.
But if you another time waits for a pid, which you alread caught
(got as a result once before), then you can wait infinite,
because that pid was caught by waitpud before... and you have to
wait until the pid is reused by the kernel or wait until next reboot. ;-)

So your concept seems to be buggy.

Ciao,
   Oliver Bandel


^ permalink raw reply	[flat|nested] 3+ messages in thread

* AW: [Caml-list] Unix.waitpid
@ 2005-06-30 13:11 Bauer, Christoph
  0 siblings, 0 replies; 3+ messages in thread
From: Bauer, Christoph @ 2005-06-30 13:11 UTC (permalink / raw)
  To: 'Oliver Bandel', caml-list

Hi,

> 
> 
> Well, using the corresponding C-API-function,
> you should better rename your arguments:
> 
>   wpid is the pid you wait for (the argument to Unix.waitpid)  and
>    pid is the value you get from that function:
> 
> 
> ===== from the wait(2)/waitpid(2)-manpage =============
>      pid_t
>      waitpid(pid_t wpid, int *status, int options);
> =======================================================
> 

Ok.

> 
> BTW: where do you set the "pid" initially?
> 

>From a Unix.create_process call.

> And: if waitpid returns with a pid, then you can't wait on this
> pid/process again. So, if you wait for one pid and get a different
> pid as result of the function call, then you wait again.
> But if you another time waits for a pid, which you alread caught
> (got as a result once before), then you can wait infinite,
> because that pid was caught by waitpud before... and you have to
> wait until the pid is reused by the kernel or wait until next 
> reboot. ;-)

Ok, then I'll use pid = 0 (or wpid = 0, after the renaming) to terminate
the loop. 

Thanks for the replies,
Christoph Bauer


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-06-30 13:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-30 12:31 AW: [Caml-list] Unix.waitpid Bauer, Christoph
2005-06-30 12:44 ` Oliver Bandel
2005-06-30 13:11 AW: " Bauer, Christoph

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).