Unix Processes

In order to launch unix commands from EusLisp, use the unix:system function. Piped-fork creates a subprocess whose standard input and standard output are connected to EusLisp's bidirectional stream through pipes. Piped-fork returns the stream. Following is a function to count the number of lines contained in a file by using "wc".

(defun count-lines (file) (read (piped-fork "wc" file)))

The next example creates eus process on another workstation identified by "etlic0" and provides a port for distributed computation.

(setq ic0eus (piped-fork "rsh" "etlic0" "eus"))
(format ic0eus "(list 1 2 3)~%")
(read ic0eus) --> (1 2 3)

For source code editing, you can call ez from the EusLisp. The screen editor ez communicates with EusLisp through message-queues. If you have an ez process already running in parallel with the EusLisp, ez restarts ez and it gains the terminal control. By issuing esc-P or esc-M commands in ez, texts are sent back and evaluated by EusLisp. This is useful for the debugging since entire file does not need to be loaded when you add a little modification to the file. Similar function is available on emacs by M-X run-lisp command.



cd &optional (dir (unix:getenv "HOME")) [function]

changes the current working directory.


ez &optional key [function]

enters display editor ez, and reads Lisp forms from it, and evaluates them.


piped-fork &optional (exec) &rest args [function]

forks a process, and makes a two-way stream between the current EusLisp and the subprocess. Exec is the file name of a unix command and args are arguments to the command. If exec (string) includes one or more space, it is assumed a shell command, and executed by /bin/sh calling the unix:system function. If no exec is given, another euslisp is created as the subprocess.


xfork exec &key (stdin *standard-input*) (stdout *standard-output*)
(stderr *error-output*) (args nil)
[function]

forks a process, replaces its stdin, stdout, and stderr streams to specified ones, and exec's "exec" with the args arguments. piped-fork is roughly equivalent to (xfork exec :stdin (unix:pipe) :stdout (unix:pipe)) Though xfork returns an io-stream to stdin and stdout with their directions reversed, it is not always useful unless they are pipes. The name of this function, xfork (cross-fork), comes from this reversed io-stream, namely, the io-stream's input comes from the stdout of the subprocess and the output comes from the stdin.


rusage [function]

prints resource usage of this process.


k-okada 2013-05-21