Disconnecting USB causes IDE to use 100% CPU on Linux

On the Ubuntu version of the Arduino IDE 1.0.5, disconnecting (unplugging) the USB cable from the PC to the Arduino Uno causes CPU usage for the Java IDE runtime to jump to 100%. What is it doing?

top - 09:43:14 up 1 day, 23:54,  4 users,  load average: 0.71, 0.60, 0.60
Tasks: 246 total,   1 running, 244 sleeping,   0 stopped,   1 zombie
%Cpu(s):  8.8 us,  5.7 sy,  0.0 ni, 85.5 id,  0.1 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem:  16376056 total, 16104688 used,   271368 free,   641840 buffers
KiB Swap: 31249404 total,        0 used, 31249404 free.  9019168 cached Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND     
 2142 nick      20   0 6874812 163476  25408 S 100.1  1.0   0:27.44 java        
                                               ^^^^^

Steps to reproduce:

  • Compile and upload Blink sketch
  • Open Serial monitor
  • Run the "top" command in a console window
  • Unplug the USB cable from the Arduino
  • Note that the java process CPU climbs from around 7% to 100%

They may be failing to check for EOF and trying to read from a "readable" file with nothing to read. At least when I write a script to read a serial port and echo to stdout it will exhibit similar behavior (when I unplug the usb cable) if I fail to have it check for EOF. When I have the script close the port on EOF there is no high cpu usage.

If some Linux users confirm this is happening to them as well I will raise a bug report on the developer site.

Confirmed. Ubuntu 14.04, 64-bit, fully updated. Java implementation: openjdk-7-jre. Dell Latitude E4310. hardinfo reports the OS as "Ubuntu 14.04.1 LTS," and the processor as "4X Inter(R) Core(TM) i5 CPU M560 2.67 GHz." Arduino IDE is 1.0.5.

Here are the first few lines from the "top" command, after unplugging the USB:

top - 22:53:28 up 1 day,  1:54,  2 users,  load average: 0.57, 0.52, 0.42
Tasks: 236 total,   1 running, 235 sleeping,   0 stopped,   0 zombie.1 
%Cpu(s): 13.6 us, 16.1 sy,  0.0 ni, 69.7 id,  0.5 wa,  0.0 hi,  0.2 si,  0.0 st
KiB Mem:   7969868 total,  6140968 used,  1828900 free,   299712 buffers
KiB Swap: 16777212 total,        0 used, 16777212 free.  3037524 cached Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND     
 3136 tom       20   0 4794744 169792  27576 S 100.1  2.1  39:00.62 java

If I use top's interactive command, "I," "Irix mode," to turn "Irix mode" to OFF, it shows this, again, after unplugging the USB:

top - 23:07:52 up 1 day,  2:08,  2 users,  load average: 1.18, 1.17, 0.90
Tasks: 238 total,   1 running, 237 sleeping,   0 stopped,   0 zombie
%Cpu(s): 18.5 us, 14.7 sy,  0.2 ni, 66.1 id,  0.5 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem:   7969868 total,  6201904 used,  1767964 free,   300460 buffers
KiB Swap: 16777212 total,        0 used, 16777212 free.  3045604 cached Mem

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND      
 3136 tom       20   0 4794744 171392  27576 S 25.0  2.2  53:25.37 java

The man page for top says that when "Irix mode" is OFF, %CPU is divided by the total number of processors. With "Irix mode" set to OFF, the %CPU reported for java matches the output of the system monitor.

Plugging the Arduino back onto the USB port didn't change anything. Closing the serial port sent java to a %CPU of 0.1 to 0.9. That seems to reflect the info posted by tf68.