(* Process *)

type status = int

val success : status = 0;

#if defined(win32)
val failure : status = 1;
#else
val failure : status = ~1;
#endif

prim_val system : string -> status = 1 "sml_system";

local
    prim_val getenv_ : string -> string = 1 "sys_getenv";
in
    fun getEnv s = (SOME (getenv_ s)) handle _ => NONE
    prim_val sleep  : Time.time -> unit = 1 "sml_sleep";
end

fun isSuccess sv = (sv = success);

val terminate = BasicIO.exit;

local 
    val exittasks = (ref []) : (unit -> unit) list ref
in 
    fun atExit newtask =
	exittasks := newtask :: !exittasks;
    fun exit status =
	(List.app (fn f => f ()) (!exittasks);
	terminate status);
end


