When a photon lands on the active part of an image sensor it has a probability of creating an electron/hole pair. This probability is known as the "quantum efficiency" of the sensor. At certain wavelengths some scientific imaging cameras can have quantum efficiencies over 90% but for a normal camera the quantum efficiency is somewhat lower.
The camera sensor is effectively an integrator, recording the amount of electric charge generated between "reset" and "readout".
Depending on the type of camera, the beginning and end of the exposure may be defined by the "reset" and "readout" processes or they may be defined by a mechanical shutter in the same way as a film camera. A mechanical shutter can provide faster shutter times and avoids rolling shutter issues but brings cost, bulk and reliability issues. Mechanical shutters are generally found on dedicated digital cameras sold for photography purposes, but are not normally found on most other types of camera (phone cameras, machine vision cameras, video cameras etc).
Some sensors, known as "global shutter" sensors can reset and readout the whole sensor array at once, but this adds complexity to the sensor array. More commonly the "reset" and "readout" processes proceed in a line by line fashion across the sensor array. This is known as a "rolling shutter" and can produce artefacts in the image. It tends to be more of an issue with short exposures though.
Unfortunately light is not the only thing that can generate electron/hole pairs. Some pairs are also generated as a result of thermal noise. This means that long exposures on digital sensors can be noisy.
On cameras with a mechanical shutter, a technique known of as dark frame subtraction can be used to reduce the noise. A second exposure is taken with the same settings but with the shutter closed. It is assumed that the noise will be similar in the "dark frame" and the regular frame and hence subtracting the dark frame will reduce the noise in the image.