The OS.Process 구조
The OS.Process 구조
OS.Process 구조는 하위 프로세스 실행, 인자, 종료 상태 등 프로세스 제어 함수를 제공해요.
출처: 문서
본문
시놉시스 (Synopsis)
signature OS_PROCESS
structure Process : OS_PROCESS
인터페이스 (Interface)
type status
val success : status
val failure : status
val isSuccess : status -> bool
val system : string -> status
val atExit : (unit -> unit) -> unit
val exit : status -> 'a
val terminate : status -> 'a
val getEnv : string -> string option
val sleep : Time.time -> unit
설명 (Description)
type status
프로세스의 종료 상태를 나타내는 타입이에요. success는 정상 종료, failure는 실패 종료예요.
val success : status
system (cmd, args)는 명령 이름 cmd와 인자 리스트 args를 사용해 하위 프로세스를 실행해요. 하위 프로세스는 시스템에 의존하는 방식으로 실행되며, 종료 상태를 돌려줘요.
val failure : status
exit는 종료 상태를 지정해 현재 프로세스 실행을 종료해요. terminate와 비슷하지만 현재 시도되는 동작 방식에 차이가 있어요.
isSuccess sts
terminate는 지정한 시그널(signum)로 현재 프로세스를 종료해요.
system cmd
환경 변수 env와 인자 args로 exec를 수행해요.
atExit f
현재 SML 프로그램이 exit를 호출할 때 실행될 동작 f를 등록해요. 동작들은 등록된 순서의 역순으로 실행돼요. f가 호출될 때 발생해 밖으로 새어 나가는 예외는 잡혀 무시돼요. f 안에서의 atExit 호출은 무시돼요. exit 호출은 반환하지 않지만, atExit에 등록된 나머지 함수들이 실행되도록 해요. terminate(또는 Posix.Process.exit 같은 유사 함수) 호출은 프로세스를 즉시 종료해요.
exit st
atExit에 등록된 모든 동작을 실행하고, Library를 사용해 연 모든 I/O 스트림을 비우고 닫은 뒤, 종료 상태 st로 SML 프로세스를 종료해요. 구현 참고: exit의 인자가 system이나 (Unix.reap 같은) 상태 값을 돌려주는 다른 함수에서 온 경우, 구현은 하위 프로세스의 종료 코드 의미를 보존하도록 노력해야 해요. 예를 들어 POSIX 시스템에서 Posix.Process.fromStatus st가 Posix.Process.W_EXITSTATUS v를 돌려주면, 필요한 정리를 모두 마친 뒤 v를 Posix.Process.exit에 넘겨야 해요. st가 종료 값을 뜻하지 않으면 exit는 failure로 호출된 것처럼 동작해야 해요. 예를 들어 POSIX 시스템에서 Posix.Process.fromStatus st가 Posix.Process.W_SIGNALED 또는 Posix.Process.W_STOPPED인 경우에 그렇게 돼요.
terminate st
atExit에 등록된 동작을 실행하거나 열린 I/O 스트림을 비우지 않고 종료 상태 st로 SML 프로세스를 종료해요.
getEnv s
환경 변수 s가 정의되어 있으면 그 값을 돌려줘요. 그렇지 않으면 NONE을 돌려줘요. 각 SML 프로세스에는 환경이 연결되어 있는데, 이는 이름-값 쌍에 해당하는 문자열 쌍의 리스트로 모델링돼요. (환경이 만들어진 방식은 호스트 운영체제에 따라 달라요.) getEnv 함수는 첫 번째 성분이 s와 같은 쌍을 환경에서 찾아요. 찾으면 두 번째 성분을 돌려줘요.
sleep t
호출한 프로세스를 t로 지정된 시간만큼 일시 중지해요. t가 0이거나 음수이면 프로세스는 잠들지 않고 즉시 반환해요. 예외는 발생하지 않아요.
더 알아보기 (Learn more)
- [ Top | Parent | Contents | Index | Root ] Generated April 12
- 2004 Last Modified October 31
- 2000 Comments to John Reppy. This document may be distributed freely over the internet as long as the copyright notice and license terms below are prominently displayed within every machine-readable copy. Copyright © 2004 AT&T and Lucent Technologies. All rights reserved. Permission is granted for internet users to make one paper copy for their own personal use. Further hardcopy reproduction is strictly prohibited. Permission to distribute the HTML document electronically on any medium other than the internet must be requested from the copyright holders by contacting the editors. Printed versions of the SML Basis Manual are available from Cambridge University Press. To order
- please visit www.cup.org (North America) or www.cup.cam.ac.uk (outside North America).