The following procedures provide raw process management.
(mosh process) is not supported on Windows.
Process | The following procedures provide raw process management. |
(mosh process) | Process Management Library |
Functions | |
fork | Fork the current process. |
exec | Replace the current process with a new external command. |
waitpid | This is an interface to waitpid(3), an extended version of wait. |
spawn | fork and exec. |
pipe | Creates a pipe, and returns two ports. |
getpid | Returns the process ID of the current interpreter process. |
call-process | Run an external command using a shell. |
start-process | Run an external command. |
process-list | Returns a process list as an a-list. |
process-terminate! | Kill process identified by OS dependent process identifier. |
Process Management Library
Functions | |
fork | Fork the current process. |
exec | Replace the current process with a new external command. |
waitpid | This is an interface to waitpid(3), an extended version of wait. |
spawn | fork and exec. |
pipe | Creates a pipe, and returns two ports. |
getpid | Returns the process ID of the current interpreter process. |
call-process | Run an external command using a shell. |
start-process | Run an external command. |
process-list | Returns a process list as an a-list. |
process-terminate! | Kill process identified by OS dependent process identifier. |
Fork the current process. Returns 0 if you’re in the child process, and a child process’ pid if you’re in the parent process. All the opened file descriptors are shared between the parent and the child. See fork(2) of your system for details.
(fork)
0 if you’re in the child process, and a child process’ pid if you’re in the parent process
Replace the current process with a new external command. The ports attached to the subprocess must be binary, and must be either file input ports or ports generated by the ‘pipe’ procedure. They can also be #f which means the subprocess inherits the parent’s ports.
(exec command args in out err . path-search? env)
command | command string to spawn. |
args | list of command line arguments. |
in | input port to attach to standard input of the subprocess. |
out | output port to attach to standard output of the subprocess. |
err | output port to attach to standard error of the subprocess. |
path-search? | optional, defaults to #t. If #t, command will be searched for in shell path, otherwise command must be an absolute path. |
env | optional association list of environment variables as strings. If specified, replaces the environment variables of the subprocess. Use an empty list to empty the subprocess environment completely. |
pid in out err is returned as multiple values.
This is an interface to waitpid(3), an extended version of wait. pid is an exact integer specifying which child(ren) to be waited. If it is a positive integer, it waits fot that specific child. If it is zero, it waits for any member of this process group. If it is -1, it waits for any child process. If it is less than -1, it waits for any child process whose process group id is equal to the absolute value of pid.
(waitpid pid)
pid | pid of process to wait. |
fork and exec.
(spawn command args . io-list path-search? env)
The same as exec, except for io-list, which is an optional list of three ports representing in, out, err respectively. (‘exec’ takes these values as separate arguments, and they are all required.) If io-list is not provided, it defaults to ‘(#f #f #f), i.e. the subprocess will inherit the parent’s ports.
;; ls -l (let-values ([(pid cin cout cerr) (spawn "ls" '("-l") (list #f #f #f))]) (waitpid pid)) ;; get output as string (let-values ([(in out) (pipe)]) (define (port->string p) (let loop ([ret '()][c (read-char p)]) (if (eof-object? c) (list->string (reverse ret)) (loop (cons c ret) (read-char p))))) (let-values ([(pid cin cout cerr) (spawn "ls" '("-l") (list #f out #f))]) (close-port out) (write (port->string (transcoded-port in (make-transcoder (utf-8-codec))))) (close-port in) (waitpid pid)))
pid in out err is returned as multiple values.
Run an external command using a shell.
(call-process command)