## spawn.api
# Compiled by:
#
src/lib/std/standard.lib# This is a threadkit version of the 'spawn' interface that is provided by Mythryl.
### "Life is pleasant. Death is peaceful.
### It's the transition that's troublesome."
###
### -- Isaac Asimov
stipulate
package fil = file; # file is from
src/lib/std/src/posix/file.pkg package psx = posixlib; # posixlib is from
src/lib/std/src/psx/posixlib.pkg package thk = threadkit; # threadkit is from
src/lib/src/lib/thread-kit/src/core-thread-kit/threadkit.pkg package sig = interprocess_signals; # interprocess_signals is from
src/lib/std/src/nj/interprocess-signals.pkgherein
api Spawn {
#
Process;
# spawn_process_in_env (path, args, env)
# forks/execs new process given by path
# The new process will have environment env, and
# arguments args prepended by the last arc in path
# (following the Unix convention that the first argument
# is the command name).
# Returns an abstract type proc, which represents
# the child process plus streams attached to the
# the child process stdin/stdout.
#
# Simple command searching can be obtained by using
# spawn_in_env ("/bin/sh", "-c" . args, env)
#
spawn_process_in_environment
:
(String, List(String), List(String))
->
Process;
# spawn (path, args)
# = spawn_in_env (path, args, psx::environ())
#
spawn_process
:
(String, List( String ))
->
Process;
spawn
:
(String, List( String ))
->
{ from_stream: fil::Input_Stream,
to_stream: fil::Output_Stream,
process: Process
};
# streamsOf proc
# Return an Input_Stream and Output_Stream used
# to read from and write to the stdout and stdin
# of the executed process.
#
# The underlying files are set to be close-on-exec.
#
streams_of
:
Process
->
( fil::Input_Stream,
fil::Output_Stream
);
# reap process
# This closes the associated streams and waits for the
# child process to finish, returns its exit status.
#
# Note that even if the child process has already exited,
# so that reap returns immediately,
# the parent process should eventually reap it. Otherwise,
# the process will remain a zombie and take a slot in the
# process table.
#
reap_mailop: Process -> thk::Mailop( psx::Exit_Status );
reap: Process -> psx::Exit_Status;
# kill (proc, signal)
# sends the Posix signal to the associated process.
#
kill: (Process, sig::Signal) -> Void;
};
end;
## COPYRIGHT (c) 1995 AT&T Bell Laboratories.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.