The following procedures provide raw process management.
(mosh process) is not supported on Windows.
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.
0 if you’re in the child process, and a child process’ pid if you’re in the parent process
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.
|pid||pid of process to wait.|
The return values are two exact integers, the first one is the child process id, and the second is a status code.
fork and exec.
(spawn command args . io-list)
|command||command string to spawn.|
|args||list of command line arguments.|
|io-list||(in out err). in, out and err should be binary-port or #f. #f means use parent’s port.|
;; 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.