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; 2+ 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] 2+ messages in thread

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

On Thu, Jun 30, 2005 at 02:09:51PM +0200, Bauer, Christoph wrote:
> 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' ()

Does you have a valid pid (as calling parameter)?
You may better use 0 or -1 in the call to Unix.waitpid.

Maybe WUNTRACED would also makes sense as flag.
Maybe better not testing with "_" in try-with.


P.S.: Documentation could be better.
I had to look in the C-API manpage to know what parameters
the Unix.aitpid awaits.
That the one arg is the pid is mentioned in the documentation, but there
is no function call example, to identify the second arg as the wpid.


Ciao,
   Oliver Bandel


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

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

Thread overview: 2+ 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

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