manpagez: man pages & more
info bigloo
Home | html | info | man
[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.7.3 Process support

Bigloo provides access to Unix-like processes as first class objects. The implementation and this documentation are to a great extent copies of the STk [Gallesio95] process support. Basically, a process contains four informations: the standard Unix process identification (aka PID) and the three standard files of the process.

bigloo procedure: run-process command arg…

run-process creates a new process and run the executable specified in command. The arg correspond to the command line arguments. When is process completes its execution, non pipe associated ports are automatically closed. Pipe associated ports have to be explicitly closed by the program. The following values of p have a special meaning:

  • input: permits to redirect the standard input file of the process. Redirection can come from a file or from a pipe. To redirect the standard input from a file, the name of this file must be specified after input:. Use the special keyword pipe: to redirect the standard input from a pipe.
  • output: permits to redirect the standard output file of the process. Redirection can go to a file or to a pipe. To redirect the standard output to a file, the name of this file must be specified after output:. Use the special keyword pipe: to redirect the standard output to a pipe.
  • error: permits to redirect the standard error file of the process. Redirection can go to a file or to a pipe. To redirect the standard error to a file, the name of this file must be specified after error:. Use the special keyword pipe: to redirect the standard error to a pipe.
  • wait: must be followed by a boolean value. This value specifies if the process must be ran asynchronously or not. By default, the process is run asynchronously (i.e. wait: if #f).
  • host: must be followed by a string. This string represents the name of the machine on which the command must be executed. This option uses the external command rsh. The shell variable PATH must be correctly set for accessing it without specifying its absolute path.
  • fork: must be followed by a boolean value. This value specifies if the process must substitute the current execution. That is, if the value is #t a new process is spawned otherwise, the current execution is stopped and replaced by the execution of command. It defaults to #t.
  • env: must be followed by a string of the form var=val. This will bound an environment variable in the spawned process. A run-process command may contain several env: arguments. The current variables of the current process are also passed to the new process.

The following example launches a process which execute the Unix command ls with the arguments -l and /bin. The lines printed by this command are stored in the file tmp/X.

(run-process "ls" "-l" "/bin" output: "/tmp/X")

The same example with a pipe for output:

(let* ((proc (run-process "ls" "-l" "/bin" output: pipe:))
       (port (process-output-port proc)))
   (let loop ((line (read-line port)))
      (if (eof-object? line)
          (close-input-port port)
          (begin
             (print line)
             (loop (read-line port))))))

One should note that the same program can be written with explicit process handling but making use of the | notation for open-input-file.

(let ((port (open-input-file "| ls -l /bin")))
   (let loop ((line (read-line port)))
      (if (eof-object? line)
          (close-input-port port)
          (begin
             (print line)
             (loop (read-line port))))))

Both input and output ports can be piped:

(let* ((proc (run-process "/usr/bin/dc" output: pipe: input: pipe:)) 
       (inport (process-input-port proc))
       (port (process-output-port proc)))
   (fprint inport "16 o")
   (fprint inport "16 i")
   (fprint inport "10")
   (fprint inport "10")
   (fprint inport "+ p")
   (flush-output-port inport)
   (let loop ((line (read-line port)))
      (if (eof-object? line)
	  (close-input-port port)
	  (begin
	     (print line)
	     (loop (read-line port))))))   -| 20

Note: The call to flush-output-port is mandatory in order to get the dc process to get its input characters.

Note: Thanks to Todd Dukes for the example and the suggestion of including it this documentation.

bigloo procedure: process? obj

Returns #t if obj is a process, otherwise returns #f.

bigloo procedure: process-alive? process

Returns #t if process is currently running, otherwise returns #f.

bigloo procedure: close-process-ports command arg…

Close the three ports associated with a process. In general the ports should not be closed before the process is terminated.

bigloo procedure: process-pid process

Returns an integer value which represents the Unix identification (PID) of the process.

bigloo procedure: process-input-port process
bigloo procedure: process-output-port process
bigloo procedure: process-error-port process

Return the file port associated to the standard input, output and error of process otherwise returns #f. Note that the returned port is opened for reading when calling process-output-port or process-error-port. It is opened for writing when calling process-input-port.

bigloo procedure: process-wait process

This function stops the current process until process completion. This function returns #f when process is already terminated. It returns #t otherwise.

bigloo procedure: process-exit-status process

This function returns the exit status of process if it is has finished its execution. It returns #f otherwise.

bigloo procedure: process-send-signal process s

Sends the signal whose integer value is s to process. Value of s is system dependent. The result of process-send-signal is undefined.

bigloo procedure: process-kill process

This function brutally kills process. The result of process-kill is undefined.

bigloo procedure: process-stop process
bigloo procedure: process-continue process

Those procedures are only available on systems that support job control. The function process-stop stops the execution of process and process-continue resumes its execution.

bigloo procedure: process-list

This function returns the list of processes which are currently running (i.e. alive).


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on March 31, 2014 using texi2html 5.0.

© manpagez.com 2000-2024
Individual documents may contain additional copyright information.