You hyperventilate right before the take, the same technique as for swimming underwater [not highly recommended underwater, but in air, of course, you can change your mind and breathe again at any time]. Also, bear in mind, you're "dead" so not doing much in the way of running around getting out of breath.
Zombies would be a whole different question and answer ;)
The idea is that you reduce the carbon dioxide levels and slightly increase oxygen levels in your lungs, reducing the urgency to breathe again quite so quickly.
It's also helpful if you're in place a good few minutes before the take, so you have time to relax and not have just rushed to set at the last minute, already breathless.
So, as you hear the 1st AD prepping for the take you breathe big and deep for 5 - 10 seconds. Each 1st AD uses a slightly different but predictable series of commands to the crew...
"Quiet, please. For a take"
"Running up"
"Roll please" [to this a dozen others yell "Turning" right across the set]
Then sound says "speed"; you hear clappers announcing the take; camera ops say "set" [which is always the final signal that everything is ready to go].
"We're turning... and.. "
"Action!"
... you over-breathe until you hear the "and" right before action[1] - then breathe right out.
Corpses do not breathe.
They do not have inflated chests, so you cannot start with an in-breath, you must have breathed right out.
Corpses that breathe get shouted at ;)
"Cut. Reset. We can see the corpse breathing."
Not a good way to use the studio's money.
Corpses that don't breathe on camera get more work than those who do.
In the rehearsal takes you keep your eyes open and watch the cameras, so you know [and can either count in your head or work from any dialogue you can hear] when you need to be mostly still. At other times you can, of course, breathe shallowly until you know you're in frame. If you're not sure and you think it might be significant - ask. Someone can count you through a rehearsal.
The other thing to note, from an audience perspective, is that long 3-minute scene where you were amazed at the corpse not breathing for the whole thing probably took a day to shoot. He probably had to not breathe for no more than 30 seconds in any individual take.
[1] The "and" before Action is often significant and highly emphasised. Background [supporting artists/extras/vehicles etc] often need to be in motion before the action actually starts to keep a fluid look to the scene. "Go on and" is a common phrase.
Just a late note on
In some movies you can tell that the picture is paused when it is on the dead character.
I don't think I've ever seen this done [I'm not saying it's never ever been done, but I've never spotted it]. The eye is really very sensitive to movement and a total still image would be quite jarring and noticeable.
After comments and other answers...
Note: it's considerably harder to hold your breath whilst breathed out, as opposed to in. You don't have the lungful of oxygen in reserve and the rise in carbon dioxide is more concentrated.
If you didn't know already, the "urgency to breathe" reflex is not triggered by lack of oxygen, but by increase in carbon dioxide concentration.
Late, late edit, 4 years after:
Just for fun, here are stills from two I had to do after this answer was posted.
One with prosthetic over the eyes, so no worries about blinking, but the scene was done in one long single shot - steadicam, over a minute's duration, ending on me for the last 10 seconds or so, while the forensics guy turns my head to camera for the gory close-up.
This second one was eyes open, staring off into infinity… and involved many cuts and fresh angles, though each take was a couple of minutes. I did have to take a breath half-way one take [because they were running two scenes back-to-back with barely time to hyperventilate between], but they cut around it easily enough. There was one camera angle for which they had to remove the wall camera left in this shot, which could have been an issue for sight line - but I got them to put a light stand with a piece of bright tape right where I needed to be looking, so sight line never changes through the entire scene. In this scene the paramedic had to pick up my arm, then drop it again, without me reacting at all.