Maybe create a simple sketch that prints a message to the serial port in setup().
Compile and upload to get the new sketch in.
Open a terminal application (not serial monitor). I used realterm (and an Uno, no Nano at hand) and it displayed the message.
Next try to compile and upload again (leave realterm connected).
If you see the message again during the compile, the board received a reset.
If not, your board did not receive a reset; and the upload will fail because avrdude could not open the serial port.
Is 2a indeed what is happening?
Thanks. OK, I haven't tried this with a simple short sketch yet. But the project I'm working on has plenty of occasional debug serial outputs, so I started there to test out RealTerm (just installed). First of all, as soon as I connect with RealTerm, it resets my board (and then of course I see my debug messages). Pressing reset (which of course resets) and debug messages are displayed. So I conclude that (a) any external opening of the USB serial port causes a board reset and (2) the IDE must be opening the port as soon as I hit UPLOAD, but then wastes time recompiling before starting the upload.
Also, not surprisingly, with RealTerm still connected, avrdude reports it cant open the comm port.
But this led to another discovery! If I shut down the realterm connection, that resets the board. Opening again does not, but closing always does. Further, if I keep both the realterm connection IDE serial monitor closed, no extra reset occurs at the instant I hit UPLOAD. So that tell me when you hit UPLOAD on the IDE, it closes the serial connection, which for some reason on my boards causes RESET. And of course it makes sense to shut down the serial monitor to upload, because serial port emulator drivers usually don't provide the port as a shared resource. (I know it can be done, but mine obviously is not). I can't repeat the experiment with the SPY feature, because I don't have that feature installed on the free version.
Now with the short sketch you provided, I still have to keep the realTerm disconnected to upload, but I see evidence of the reset still happening twice... once when I hit UPLOAD, and again when the upload completes. Its pretty obvious because the blinking LED from the last U/L freezes when I click UPLOAD, and then of course momentarily freezes again when the upload completes. Again, keeping the serial monitor closed avoids the unwanted initial reset.
OK... if that's the way it works. I can live with it. Thanks again.