Running without a Display

Daniel Shiffman edited this page Nov 14, 2015 · 5 revisions

Let's say you want to run a Processing sketch on a server. Like maybe you want to generate several million PDF and JPEG images using a handful of Amazon EC2 instances.

This is called “headless” mode, and to do so, it's necessary to install what's known as a virtual frame buffer.

On Ubuntu 14.04, these are the things you need to install first:

sudo apt-get install xvfb libxrender1 libxtst6 libxi6 

Then you create a fake "display" that Processing can use:

sudo Xvfb :1 -screen 0 1024x768x24
export DISPLAY=":1"

Finally, run a sketch that's been exported as a Linux application from the PDE.

The above assumes that Java is already installed. If Java is not installed, you'll need to do something like:

sudo apt-get install default-jdk

You don't actually need the JDK to run the sketch so this is also ok:

sudo apt-get install default-jre

Make sure you do not specify a "headless" Java (for example openjdk-7-jre-headless), as then the simulated window trick will no longer work.

Why?

It's necessary to use the virtual frame buffer because it would require a truly ridiculous amount of work to make Processing so general that it could be done without a display. This would involve a great deal of code and abstraction that simply doesn't make sense when 99.9999% of the code created with Processing will be run with a display. Happily, this method works well and prevents us from needing to double the size of PApplet.

Headless Mode

Another option is to mess with the command line parameters that launch Java. If you add -Djava.awt.headless=true to the line that runs the java command, that may be all you need. Read more about Java's Headless Mode here. For most cases, this is less likely to work, but may provide clues for how to get a more complicated sketch running on your machine.