caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* RE: [Caml-list] Unix.system returns "no child processes"
@ 2005-12-10  0:15 Harrison, John R
  0 siblings, 0 replies; 2+ messages in thread
From: Harrison, John R @ 2005-12-10  0:15 UTC (permalink / raw)
  To: Christopher Conway; +Cc: caml-list, Harrison, John R

Hi Chris,

| I am using Unix.system to invoke external commands from within Ocaml.
On 
| the old machines (with the 32-bit version of Ocaml), I would 
| occasionally get the exception Unix_error(ECHILD,"waitpid","") from 
| Unix.system. With the new machines, I'm seeing this at every call to 
| Unix.system, every time. I have investigate the behavior of the 
| sub-processes, and they are terminating normally, with no indication
of 
| any error.

I also sometimes see the intermittent error:

   Exception: Unix.Unix_error (Unix.ECHILD, "waitpid", "").

But what I'm doing with the system call is sufficiently sleazy that I
probably deserve it. I'm running OCaml under the checkpointing program
"ckpt". The following function is supposed to make the session
checkpoint itself, then print a startup banner when execution is
resumed:

  let self_destruct bannerstring =
    let complete_banner =
      if bannerstring = "" then startup_banner
      else startup_banner^"\n        "^bannerstring in
    Gc.compact();
    let pid = string_of_int(Unix.getpid()) in
     (ignore(Unix.system("kill -USR1 "^pid));
      Format.print_string complete_banner;
      Format.print_newline(); Format.print_newline());;

Sometimes I get the exception above instead of the banner when the
process restarts. The likelihood of that happening seems highly
machine-dependent, and even on a given machine there's no obvious
pattern.

John.


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

* Re: [Caml-list] Unix.system returns "no child processes"
  2005-12-09 19:35 Christopher Conway
@ 2005-12-09 20:26 ` Olivier Andrieu
  0 siblings, 0 replies; 2+ messages in thread
From: Olivier Andrieu @ 2005-12-09 20:26 UTC (permalink / raw)
  To: Christopher Conway; +Cc: caml-list

> Christopher Conway wrote:
> I am using Unix.system to invoke external commands from within Ocaml. On
> the old machines (with the 32-bit version of Ocaml), I would
> occasionally get the exception Unix_error(ECHILD,"waitpid","") from
> Unix.system. With the new machines, I'm seeing this at every call to
> Unix.system, every time. I have investigate the behavior of the
> sub-processes, and they are terminating normally, with no indication of
> any error.

the linux manpage for waitpid has this:

ERRORS
       ECHILD if the process specified in pid does not exist or is not a
child of the calling process.  (This can
              happen  for  one’s  own child if the action for SIGCHLD is
set to SIG_IGN. See also the LINUX NOTES
              section about threads.)

This begs the question: did you setup the SIGCHLD handler to SIG_IGN ? or
are you using threads ?

>
> I have a theory why this is happening, but no supporting evidence. It
> goes like this: system is basically fork+execv+waitpid; on the new
> machines, fork+execv is terminating so quickly that the process is gone
> before the call to waitpid.

No, the process should stay as a zombie (unless you've set a signal
handler for SIGCHLD I guess)

-- 
  Olivier


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

end of thread, other threads:[~2005-12-10  0:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-10  0:15 [Caml-list] Unix.system returns "no child processes" Harrison, John R
  -- strict thread matches above, loose matches on Subject: below --
2005-12-09 19:35 Christopher Conway
2005-12-09 20:26 ` [Caml-list] " Olivier Andrieu

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