Processing & Arduino connection

Hello everybody,

I'm using the Arduino Duemilinova.

I've connected my arduino with processing and got it to do stuff that i wanted.

But now I want the arduino board to do some other things when processing closes and in particular when the connection from the usb is cut off.

I need to modify firmata to check if there is a connection with the pc. How can i do that?