Version française
Home     About     Download     Resources     Contact us    
Browse thread
AW: [Caml-list] Unix.waitpid
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Oliver Bandel <oliver@f...>
Subject: Re: [Caml-list] Unix.waitpid
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