Unix
structure
The Unix structure provides several high-level functions for creating and communicating with separate processes, in analogy with the popen
interface provided in the Unix operating system. This provides a more flexible interface than that provided by the OS.Process.system function. Using this module, a program can invoke a separate process and obtain input and output streams connected to the TextIO.stdOut and TextIO.stdIn streams, respectively, of the other process.
signature UNIX
structure Unix
: UNIX
type proc
type signal
val executeInEnv : (string * string list * string list) -> proc
val execute : (string * string list) -> proc
val streamsOf : proc -> (TextIO.instream * TextIO.outstream)
val reap : proc -> OS.Process.status
val kill : (proc * signal) -> unix
type proc
type signal
type signal = Posix.Signal.signal
.
executeInEnv (cmd, args, env)
"NAME=VALUE"
. See also OS.Process.getEnv.) A proc value representing the new process is returned.
execute (cmd, args)
For implementations providing Posix modules, this function is equivalent to executeInEnv (cmd, args, Posix.ProcEnv.environ ())
.
streamsOf pr
(ins, outs)
of input and output streams associated with pr. When the process pr is created, its TextIO.stdOut becomes the source for the stream ins and the output stream outs becomes the source for its TextIO.stdIn.
reap pr
kill (pr,s)
Note that the interpretation of the string cmd depends very much on the underlying operating system. Typically, the cmd argument will be a full pathname. On Unix systems, simple command searching, allowing cmd to be a relative pathname, can be achieved by, for example, replacing cmd with /bin/sh
and replacing the argument list args with "-c"::(concat (cmd::args))
.
The semantics of Unix necessitates that processes that have terminated need to be reaped. If this is not done, information concerning the dead process continues to reside in system tables. Thus, a program using execute
or executeInEnv
should invoke reap
on any process it creates.
Implementation note:
Although the flavor of this module is heavily influenced by Unix, and the module is simple to implement given the Posix subsystem, the functions are specified at a sufficiently high-level that implementations, including non-Unix ones, could provide this module without having to supply all of the Posix modules.
Posix, Posix.Signal, Posix.ProcEnv, TextIO, OS.Process
Last Modified January 31, 1997
Comments to John Reppy.
Copyright © 1997 Bell Labs, Lucent Technologies