Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/compiler/PervEnv/Unix/os-process.sml
ViewVC logotype

Annotation of /sml/trunk/src/compiler/PervEnv/Unix/os-process.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 16 - (view) (download)

1 : monnier 16 (* os-process.sml
2 :     *
3 :     * COPYRIGHT (c) 1995 AT&T Bell Laboratories.
4 :     *
5 :     * The Posix-based implementation of the generic process control
6 :     * interface (OS.Process).
7 :     *
8 :     *)
9 :    
10 :     structure OS_Process : OS_PROCESS =
11 :     struct
12 :    
13 :     structure P_Proc = Posix.Process
14 :     structure CU = CleanUp
15 :    
16 :     type status = OS.Process.status (* int *)
17 :    
18 :     val success = 0
19 :     val failure = 1
20 :    
21 :     fun system cmd = (case P_Proc.fork()
22 :     of NONE => (
23 :     P_Proc.exec ("/bin/sh", ["sh", "-c", cmd])
24 :     P_Proc.exit 0w127)
25 :     | (SOME pid) => let
26 :     fun savSig s = Signals.setHandler (s, Signals.IGNORE)
27 :     val savSigInt = savSig UnixSignals.sigINT
28 :     val savSigQuit = savSig UnixSignals.sigQUIT
29 :     fun restore () = (
30 :     Signals.setHandler (UnixSignals.sigINT, savSigInt);
31 :     Signals.setHandler (UnixSignals.sigQUIT, savSigQuit);
32 :     ())
33 :     fun wait () = (case #2(P_Proc.waitpid(P_Proc.W_CHILD pid, []))
34 :     of P_Proc.W_EXITED => success
35 :     | (P_Proc.W_EXITSTATUS w) => Word8.toInt w
36 :     | (P_Proc.W_SIGNALED s) => failure (* ?? *)
37 :     | (P_Proc.W_STOPPED s) => failure (* this shouldn't happen *)
38 :     (* end case *))
39 :     in
40 :     (wait() before restore())
41 :     handle ex => (restore(); raise ex)
42 :     end
43 :     (* end case *))
44 :    
45 :     val atExit = AtExit.atExit
46 :    
47 :     fun terminate x = P_Proc.exit(Word8.fromInt x)
48 :     fun exit sts = (CU.clean CU.AtExit; terminate sts)
49 :    
50 :     val getEnv = Posix.ProcEnv.getenv
51 :    
52 :     end
53 :    
54 :     (*
55 :     * $Log: os-process.sml,v $
56 :     * Revision 1.3 1997/11/25 22:40:37 jhr
57 :     * The type of General.before has changed.
58 :     *
59 :     * Revision 1.2 1997/08/20 13:09:49 jhr
60 :     * Lifted OS independent atExit code into its own module, and fixed an
61 :     * infinite loop that occurred when an atExit action called exit.
62 :     *
63 :     * Revision 1.1.1.1 1997/01/14 01:38:25 george
64 :     * Version 109.24
65 :     *
66 :     *)

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0