module Proc:An Ocaml abstraction for UNIX processes. Thesig
..end
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.
exception Not_child
type
t
typestatus =
Unix.process_status
=
| |
WEXITED of |
(* | The process terminated normally by exit; the argument is the return code. | *) |
| |
WSIGNALED of |
(* | The process was killed by a signal; the argument is the signal number. | *) |
| |
WSTOPPED of |
(* | The process was stopped by a signal; the argument is the signal number. | *) |
Unix.process_status
val fork : unit -> t option
Some t
in the parent and None
in the childval spawn : ?quiet:bool -> (unit -> unit) -> t
Proc.t
. Proc.spawn
will not allow control in the subprocess to return to its caller; to
this end, it catches all exceptions, printing a message and then
exiting with status 2. The optional argument ?quiet
(default
false) suppresses the message.val kill : ?raise:bool -> int -> t -> unit
Proc.kill n p
sends signal n
to process p
. The optional argument ?raise
(default true
)
specifies whether to raise an exception if the process doesn't
exist or we aren't allowed to kill it.
Raises Unix.Unix_error
(see Unix.kill
)
val wait : t -> status
Proc.wait proc
performs a blocking wait on proc
;
if the child has already exited, it returns immediately.
Unlike Unix.waitpid
, Proc.wait
may
be called multiple times for the same process. If proc
is not a child
of the calling process, raises Proc.Not_child
.val wait_any : t list -> t
Proc.t
s, return any one of them that has exited.
If one has exited already, it return immediately, but if all are still
running, it blocks. Calling Proc.wait_any
may reap children
other than those in the list.
Raises Not_child
if given the empty list or any non-children.
val status_of_proc : t -> status option
Proc.Not_child
if proc
is not a child of the calling
process.val is_child : t -> bool
val pid_of_proc : t -> int
proc
val proc_of_pid : int -> t
Proc.t
associated with a UNIX
process. If there is no Proc.t
but the process exists, it constructs
one. Raises Not_found
if there is no process with the given process id,
or Invalid_argument "procs_of_pid"
if the pid is non-positive.val procs_of_pid : int -> t list
Proc.t
s with the given process id.
There may be more than one if the same process id has been used
multiple times (rarely).val exit_with_status : status -> 'a
val autoreap : unit -> unit
Proc.wait
or Proc.status_of_proc
.val don't_autoreap : unit -> unit
Proc.wait
and Proc.status_of_proc
will still work, but the user is
responsible to reap all processes.val system : string -> status
Unix.execv
.
This function delegates to the shell for argument parsing; if you
already have a list, use Proc.system_program
.
val system_program : ?path:bool -> string -> ?argv0:string -> string list -> status
?path
(default true
) specifies whether
to search the path, and ?argv0
(default prog
) specifies
an alternate value for the new process's argv.(0)
.
If Unix.execv
raises an exception in the child process,
Proc.system_program
re-raises the exception on the parent process.
This function takes an already-parsed argument list. To have the
shell do it, use Proc.system
.
val vfork : string -> t
Proc.system
, but doesn't wait.val vfork_program : ?path:bool -> string -> ?argv0:string -> string list -> t
Proc.system_program
, but doesn't wait.val exec : string -> 'a
Proc.vfork
, but doesn't fork.val exec_program : ?path:bool -> string -> ?argv0:string -> string list -> 'a
Proc.vfork_program
, but doesn't fork.execspec
Record. type
execspec = {
|
path : |
(* | 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
It's also possible to construct a Much of this design is due to Cash/Scsh. | *) |
|
program : |
(* | 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
It's also possible to construct a Much of this design is due to Cash/Scsh. | *) |
|
argv0 : |
(* | 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
It's also possible to construct a Much of this design is due to Cash/Scsh. | *) |
|
args : |
(* | 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
It's also possible to construct a Much of this design is due to Cash/Scsh. | *) |
Proc.exec_program
and
Proc.system_program
) take the same arguments to specify a
program to execute. It's sometimes
helpful to package these arguments in a record and pass them to such
a function later.val execspec : ?path:bool -> string -> ?argv0:string -> string list -> execspec
val with_execspec : execspec ->
(?path:bool -> string -> ?argv0:string -> string list -> 'a) -> 'a
Proc.execspec
.
For example,
Proc.with_execspec (Proc.execspec ~path program ~argv0 args) f
calls
f ~path program ~argv0 args
.