Most Arduino boards auto-reset when the serial port opens. This is the case with the Arduino Uno, Mega and Nano.
If you wish to prevent this auto-reset, use either one of the following methods. If none of these works for you, please have a look at the dedicated Arduino Playground article which presents other solutions.
1) Adding a 100nF capacitor
This is by far the simplest solution which should work with most of your boards. The auto-reset is triggered by the DTR line on the serial connection which goes low for a short moment just after serial port opening. To cancel the effect of the DTR line, simply plug a 100nF ceramic capacitor between the GND and RESET lines on your board.
2) Using boards which does not auto-reset
Some Arduino boards do not auto-reset when the serial port opens. This is the case of the Arduino Leonardo and Micro. You can use one of those if it fits your needs.