Module Proc


module Proc: sig .. end
An Ocaml abstraction for UNIX processes. The Proc module takes responsiblity for reaping children and provides access to exit codes through abstract Proc.t objects. (If you need to reap yourself, Proc.don't_autoreap will turn off the Sys.sigchld handler, and Proc.autoreap will turn it back on.)

Because the Proc module is responsible for reaping, it makes exit status available as many times as necessary, though Proc.wait and Proc.status_of_proc.

It's also possible to construct a Proc.t object from a pid (int) even if the process wasn't created using this library. In this case, the library detects whether the process is a child or not. We don't allow waiting on or getting the status of non-child processes, because UNIX doesn't.

Much of this design is due to Cash/Scsh.



Types


exception Not_child
Raised on attempts to get the exit status of a process that isn't a child of the current process
type t 
The abstract type of a process representation
type status = Unix.process_status = 
| WEXITED of int (*The process terminated normally by exit; the argument is the return code.*)
| WSIGNALED of int (*The process was killed by a signal; the argument is the signal number.*)
| WSTOPPED of int (*The process was stopped by a signal; the argument is the signal number.*)

Process Management


val fork : unit -> t option
Return Some t in the parent and None in the child
val spawn : ?quiet:bool -> (unit -> unit) -> t
val kill : ?raise:bool -> int -> t -> unit
val wait : t -> status
val wait_any : t list -> t
val status_of_proc : t -> status option
val is_child : t -> bool
val pid_of_proc : t -> int
val proc_of_pid : int -> t
val procs_of_pid : int -> t list
val exit_with_status : status -> 'a
val autoreap : unit -> unit
val don't_autoreap : unit -> unit
val system : string -> status
val system_program : ?path:bool -> string -> ?argv0:string -> string list -> status
val vfork : string -> t
val vfork_program : ?path:bool -> string -> ?argv0:string -> string list -> t
val exec : string -> 'a
val exec_program : ?path:bool -> string -> ?argv0:string -> string list -> 'a

type execspec = {
   path : bool option; (*Search the path (default true)*)
   program : string; (*Executable to run*)
   argv0 : string option; (*Zeroth argument (default program)*)
   args : string list; (*Additional arguments*)
}
val execspec : ?path:bool -> string -> ?argv0:string -> string list -> execspec
Constructs an Proc.execspec, given the same arguments as Proc.exec_program.
val with_execspec : execspec ->
(?path:bool -> string -> ?argv0:string -> string list -> 'a) -> 'a