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

Hi,

my app should wait for some processes. This is done 
by my function wait, which gets a pid, a idle function (e.g. ignore)
+ its value and a delay time between polling:


let delay s = ignore (Unix.select [] [] [] s)

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' ()

It works mostly, but in some rare, non-deterministic cases wait loops
forever.
In a seconds round it works without problems. I saw this behaviour on Linux
and Windows. Can anybody help me?

Thanks!

Christoph Bauer
Dipl. Inf.

LMS Deutschland GmbH
Luxemburgerstr. 7
D-67657 Kaiserslautern

T +49 631 303 22 152

mailto:Christoph.Bauer@lms-gmbh.de
http://www.lmsintl.com 


^ permalink raw reply	[flat|nested] 3+ messages in thread
* 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

end of thread, other threads:[~2005-06-30 12:45 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:09 Unix.waitpid Bauer, Christoph
2005-06-30 12:35 ` [Caml-list] Unix.waitpid Oliver Bandel
2005-06-30 12:31 AW: " Bauer, Christoph
2005-06-30 12:44 ` Oliver Bandel

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