[ ECLiPSe Operating System built-in.|Group Index| Full Index]

exec_group(+Command, ?Streams, ?Pid)

A child process Command is forked in a new process group, its standard streams are connected to Streams and its process ID is Pid.

+Command
String, atom or list of atomic terms.
+Streams
List, partial list, nil or a variable.
?Pid
Integer or a variable.

Description

This predicate is used to fork a child process in its own process group and to set up pipes to its standard streams. After the process is forked, ECLiPSe continues normally, without waiting for the child to terminate. The first word in Command specifies the program to be executed, following words are its command-line arguments. Since the child process is in a new process group, it does not get the interrupt, hangup and kill signals sent to the parent. This feature might be needed if e.g. a separate ECLiPSe process is forked which should not be influenced when the user types Ctrl-C to the main ECLiPSe process.

By specifying the Streams argument it is possible to control which of the process' standard streams are connected to ECLiPSe streams. The form of Streams is [Stdin, Stdout, Stderr]. If some of these streams are specified and not null, a pipe is opened which connects the standard stream of the child process with the specified ECLiPSe stream, e.g. Stdin must be an output stream because it is connected to the standard input of the child process. If the list Streams is shorter, only the specified streams are connected with a pipe. The streams can be specified like for open/3. If the stream is a variable, it is bound to the physical stream number, if it is an atom different from null, that symbolic stream is used. Specifying a null stream means that no pipe is set up for this stream.

Each stream can also be specified as sigio(Stream) (BSD systems only). In this case a pipe is set up to the stream Stream and in addition the pipe is instructed to send the signal io each time new data appears in it. In this way the two processes can communicate in a truly asynchronous way. When one process sends data to the other one, the interrupt handler is invoked and it can read and process the data. When it finishes, it can continue where it was interrupted.

After forking the process, Pid is unified with its process ID, which can be used e.g. in wait/2 or kill/2. If the exec system call in the child process failed, the child exits with status 128 + errno.

Fail Conditions

Fails if Pid does not unify with the process ID of the child process.

Resatisfiable

No.

Exceptions

(4) Instantiation fault
Command is not instantiated.
(5) Type error
Command is instantiated, but not to a string or an atom.
(5) Type error
Streams is instantiated, but not to a list.
(5) Type error
A stream in Streams is instantiated, but not to an atom or a sigio structure.
(5) Type error
Pid is instantiated, but not to an integer.
(170)
System error, it was not possible to fork the child.
(192)
The specified stream is not open in the appropriate mode.

Examples


Success:
      % the child process does not get the signal if ^C is typed
      [eclipse]: exec_group(eclipse, [output], Pid).

      Pid = 11459
      yes.
      [eclipse]:
      ECLiPSe Version 3.0 beta, 5/16/90 Copyright ECRC GmbH
      [eclipse]: ^C
      interruption: type a, b, c, e, or h for help : ?

      % when exec/3 is used, both processes get the signal
      [eclipse]: exec(eclipse, [output], Pid).

      Pid = 11440
      yes.
      [eclipse]:
      ECLiPSe Version 3.0 beta, 5/16/90 Copyright ECRC GmbH
      [eclipse]: ^C

      interruption: type a, b, c, e, or h for help : ?
      interruption: type a, b, c, e, or h for help : ?
Error:
      exec_group(S, [], Pid).          (Error 4).
      exec_group(ls, null, Pid).       (Error 5).
      exec_group(chipc, [1], P).       (Error 5).
      exec_group(date, [input], P).    (Error 192).


See Also

exec / 2, exec / 3, kill / 2, sh / 1, system / 1, open / 3, wait / 2