The Standard ML Basis Library


The Posix.Process structure

The structure Posix.Process describes the primitive POSIX operations dealing with processes, as described in Section 3 of the POSIX standard [CITE]1003.1,1996/.


Synopsis

signature POSIX_PROCESS
structure Process : POSIX_PROCESS

Interface

eqtype signal
eqtype pid
val wordToPid : SysWord.word -> pid
val pidToWord : pid -> SysWord.word
val fork : unit -> pid option
val exec : (string * string list) -> 'a
val exece : (string * string list * string list) -> 'a
val execp : (string * string list) -> 'a
datatype waitpid_arg  = W_ANY_CHILD  | W_CHILD of pid   | W_SAME_GROUP  | W_GROUP of pid
datatype exit_status  = W_EXITED  | W_EXITSTATUS of Word8.word   | W_SIGNALED of signal   | W_STOPPED of signal
structure W : sig
    include POSIX_FLAGS
    val untraced : flags
  end
val wait : unit -> (pid * exit_status)
val waitpid : (waitpid_arg * W.flags list) -> (pid * exit_status)
val waitpid_nh : (waitpid_arg * W.flags list) -> (pid * exit_status) option
val exit : Word8.word -> 'a
datatype killpid_arg  = K_PROC of pid   | K_SAME_GROUP  | K_GROUP of pid
val kill : (killpid_arg * signal) -> unit
val alarm : Time.time -> Time.time
val pause : unit -> unit
val sleep : Time.time -> Time.time

Description

eqtype signal
represents a POSIX signal.

eqtype pid
is an handle for an operating system process.

wordToPid i
converts the word i to a process ID. Note that no validation is done to ensure the pid thus generated is legal on the given system or that is corresponds to a currently running process.

pidToWord pi
converts a process ID pi to a word.

fork ()
creates a new process. The new child process is a copy of the calling parent process. After execution of fork, both the parent and child process execute independently, but share various system resources. Upon successful completion, fork returns NONE in the child process, and the pid of the child in the parent process. Raises OS.SysErr on failure.

exec (path, args)
exece (path, args, env)
execp (file, args)
These functions replace the current process image with a new process image. There is no return from a successful call, as the calling process image is overlaid by the new process image. In the first two forms, the path argument specifies the pathname of the executable file. In the last form, if file contains a slash character, it is treated as the pathname for the executable file; otherwise, an executable file with name file is searched for in the directories specified by the environment variable PATH.

Normally, the new image is given the same environment as the calling program. The env argument in exece allows the program to specify a new environment.

The args argument is a list of string arguments to be passed to the new program. By convention, the first item in args is some form of the file name of the new program, usually the last arc in the path or file name.

datatype waitpid_arg
W_ANY_CHILD
wait for any child process

W_CHILD of pid
wait for the child process with the given pid

W_SAME_GROUP
wait for the child process in the same process group of the calling process

W_GROUP of pid
wait for any child process whose process group id is given by pid.

datatype exit_status
W_EXITED
exited with no error

W_EXITSTATUS of Word8.word
exited with the given error value

W_SIGNALED of signal
exited due to the receipt of the given signal

W_STOPPED of signal
stopped due to the receipt of the given signal

structure W

untraced
is a flag that may be used, in systems supporting job control, to report the status of processes that have been stopped.

wait ()
allows a calling process to obtain status information of any of its child processes. Execution of wait suspends execution until the status information of one of its terminated child processes is available. If status information is available prior to the execution of wait, return is immediate. wait returns the process ID of the child and its exit status.

waitpid (wa, l)
is identical to wait except that status is reported for child processes specified by wa. A list of flags l may be used to modify the behavior of waitpid.

waitpid_nh (wa, l)
is identical to waitpid, except that the the call does not suspend if status information for one of its children specified by wa is not immediately available.

exit i
terminates the calling process. If the parent process is executing a wait related call, the exit status i is made available to it. exit does not return to the caller.

Calling exit does not flush or close any open IO streams, nor does it call OS.Process.atExit. It does close any open POSIX files, and performs the actions associated with the C version of exit.

datatype killpid_arg
K_PROC of pid
send signal to process with given pid.

K_SAME_GROUP
send signal to all processes in the same process group as the calling process.

K_GROUP of pid
send signal to all processes in the process group specifies by pid.

kill (ka, si)
sends the signal si to the process or group of processes specified by ka.

alarm ti
causes the system to send an alarm signal (alrm) after ti seconds have elapsed. If there is a previous alarm request with time remaining, the alarm function returns a nonzero value that is the number of seconds remaining on the previous request. Zero time is returned if there are no outstanding calls.

pause ()
suspends the calling process until the delivery of a signal that is either caught or that terminates the process.

sleep ti
causes the current process to be suspended from execution until either ti seconds have elapsed, or until the receipt of a signal that is either caught or that terminates the process.


See Also

POSIX_FLAGS, Posix, Posix.Signal, OS

[ INDEX | TOP | Parent | Root ]

Last Modified April 18, 1996
Comments to John Reppy.
Copyright © 1997 Bell Labs, Lucent Technologies