Many Mac users use utilities to temporarily prevent their computer from sleeping, often relying on sleep corners, the third party tool called Caffeine, pmset, or more recently, the command line utility that is now bundled with OS X called caffeinate. By default, the Caffeine menubar item and the caffeinate command both will prevent sleep as long as they are individually activated for, very useful for desktop users while at a Mac, but not particularly useful if you’d like to have the OS X sleep function dependent on the completion of a specific process or task.
That’s what we’re going to cover here by using the command line, which is having process-dependent sleep prevention that only blocks the Mac sleep function while a specified command, task, or process is running or active, then when it’s finished, the computer will restore traditional sleep habits.
Full article here:
Prevent System Sleep While a Process or Command is Active in Mac OS X (OS X Daily)