Working with a computer generates periods of "wasted" or "dead" time. I'm talking about the time during which the computer compiles your program, performs a sophisticated computation or downloads an important file. These periods of time can be about 1 to 5 minutes and there is nothing you can do about it. Usually, I go to the news site, read mails, follow Twitter, but then I find myself spending way too much time on these side activities, much longer than the original delay.

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.
If this question can be reworded to fit the rules in the help center, please edit the question.

If I'm working at home, I'm setting the job to ring an audible bell (I like working in screen, so when I'm waiting for something to complete, I just switch windows and screen will notify me of any new output in the background window), or display a widely visible notification when done. I then can go around and do some household chores, each of them dreaded but not taking much time, so I re-check the computer frequently enough to not miss anything (be it error or successful termination) for a longer period of time. There's a risk of chores taking more time than needed for the compute task, but the overlap is usually worth parallelizing.

At work, there's usually a few smaller tasks worth doing in-between, so I'm reviewing mail, to-do lists, shelve away stuff that has piled up on my desk, or do other things that don't keep me engaged for too long and have a tendency to fall through the grid.

And of course, there's always the coffee-cup-commute to the kitchen :)

More directly to the point, I look for activities that are easy to timebox into a short frame.

I might browse an RSS feed, and pop anything I want to read into a new window. That's the task, done, back to work.

Or review questions here, pop each one I want to look at into a new window, and I'm done, back to work.

Or look at one (just one) of the windows I'd previously opened. Respond if I'm going to, then close the window. And I'm done, back to work.

The trick is to timebox aggressively - not "I'll look at Productivity.Stackexchange" but "I'll review the new questions at Productivity.Stackexchange for anything to look at in more detail" followed by another timeboxed activity, "I'll look at one question."

I happen to have a good example which is part of my life that shows how this is a problem.

I come earlier than the normal worker to the office, so it's pretty calm and nobody's around. Also, I always leave my computer on, and it usually keeps on on its battery from one day to another (it's a notebook and I leave it sleeping). However, when I come in on Mondays, the battery didn't hold so a long startup session commences, and then the corporate virus scan runs, all my dev services starts up. I might as well have half an hour where I can literary do nothing on the computer.

First approach is try to avoid it.

If possible, avoid those times happening. On my case, I could find out how to make the computer hibernate, or how to prevent it from taking so long on its startup. If you're dealing with downloads, then maybe do something else and leave stuff downloading when you're out to lunch.

Second approach is to be prepared.

As others correctly said, it would be a good idea to make use of that time. I am thinking in bringing in a book, or even better, my iPad, so I can read a book or start checking emails right away while my working machine starts up. You may want to do pushups as Casebash said, or check email, or get some coffee. Whatever would interrupt you later and you can do in this little time, is a perfect candidate for doing on those dead times.

Third approach (complementary) is to start identifying them.

I think that if you're asking this question, you're on the right path, but there are possible some other dead times and interruptions that are not as obvious as my example and you still deal with them day to day. Start thinking about those (you can even use those dead times for it!) and how you could avoid them or use that time in a better way.

Also, really good question. So good that you made me write advice for myself.

At work I go out of the room and say hello to my colleagues in another room. Chatting a bit helps refresh your mind better than many other activities. You also start looking as a more social person (which can be a good thing for a programmer), if you don't bother them too much.

Not a full solution, but try to configure software scripts etc to display absolute start and end times, and duration at the end of the job.

Duration is important to keep an eye on how long it took to perform the job. If a job starts to take longer then that's because something changed and there may be things you can do to speed it up. If the job creates a list of events, thse should have absolute times so you can review the tempo of each part of the job.

Absolute end time helps you to understand if your dead-time activity has overrun, which can help you tune your choice of tasks.

Start time is useful in exceptional scenarios, when you have those "what just happened?" moments, and for calculating duration if necesary.

Not the most ideal solution, but whenever I have downtime of my main computer working, I move to my laptop and do something else on there until the wait process is over.

In a work environment, I had a build that took in excess of 30 minutes to compile and run the thousands of test cases present. Given the long wait period, I scheduled this process for when I'd go on lunch break or go home. This is great way to avoid those long waits without losing time to be productive.