1 fun statusToString status
=
3 Posix
.Process
.W_EXITED
=> "W_EXITED"
4 | Posix
.Process
.W_EXITSTATUS w
=> concat
["W_EXITSTATUS ", Word8.toString w
]
5 | Posix
.Process
.W_SIGNALED s
=>
6 concat
["W_SIGNALED ", SysWord
.toString (Posix
.Signal
.toWord s
)]
7 | Posix
.Process
.W_STOPPED s
=>
8 concat
["W_STOPPED ", SysWord
.toString (Posix
.Signal
.toWord s
)]
10 val cmd
= CommandLine
.name ()
13 TextIO.output (TextIO.stdOut
, "Hello world! [stdout]\n")
14 fun exit () = Posix
.Process
.exit
0wx7
15 fun diverge () = diverge ()
21 val _
= TextIO.flushOut (TextIO.stdOut
)
22 val _
= TextIO.flushOut (TextIO.stdErr
)
25 {path
= cmd
, args
= [cmd
, arg
]}
30 Posix
.Process
.waitpid (Posix
.Process
.W_CHILD pid
, [])
33 then raise Fail
"reap: pid <> pid'"
38 fun kill (pid
, signal
) =
39 Posix
.Process
.kill (Posix
.Process
.K_PROC pid
, signal
)
40 fun doTest (arg
, withPid
) =
42 val _
= print (concat
["testing ", arg
, "...\n"])
45 val status
= waitpid pid
46 val _
= print (concat
["exit_status: ", statusToString status
, "\n"])
50 fun doSimpleTest arg
= doTest (arg
, fn _
=> ())
53 ; doSimpleTest
"stdout"
55 ; doTest ("diverge", fn pid
=> kill (pid
, Posix
.Signal
.kill
))
59 case CommandLine
.arguments () of
61 |
["stdout"] => stdout ()
63 |
["diverge"] => diverge ()