Skip to content

Latest commit

 

History

History
77 lines (54 loc) · 1.64 KB

process.md

File metadata and controls

77 lines (54 loc) · 1.64 KB

Process

Process represents a running application in an LXD container, you can run multiple processes at the same time and wait on them individually.

Starting

To run processes you must obtain the Container instance.

container.exec(["sleep", "5"], function(err, process) {
  if (err != null) {
    console.error(err);
    return;
  }

  process.on("close", function() {
      console.log("process closed");
  });
});

You can find more examples of executing programs in the Container documentation.

Stopping

You can forcibly close a process by calling close.

process.close();

Events

You can read data output by using the standard EventEmitter subscription functions. The same event is called when data is written to standard output and error.

process.on("data", function(isStdErr, data) {
  if (isStdErr)
    console.error(data);
  else
    console.log(data);
});

You can wait for the process to close by hooking the close event.

process.on("close", function() {
  console.log("process closed!");
});

You can optionally check the isClosed method to check if a process has closed.

console.log(process.isClosed());

Resizing

You can resize the virtual terminal attached to the process by calling resize. There is no confirmation callback for this operation.

process.resize(300, 400);

Input

You can write to standard input using write. You can write raw binary data or UTF8 strings. There is no confirmation callback for this operation.

// write some text
process.write("Alan\n");

// write binary
process.write(new Buffer("UnVzdHkgU3BhdHVsYQ==", "base64"));