Terminal Oops: Resume a Stopped Process in OSX, Linux, or UNIX

Jun 20 2012

Have you ever accidentally suspended or stopped a process in your shell? In UNIX, Linux, and Mac OSX it is easy enough to do. An accidental hit to CTRL-z will suspend a program, returning a message like this:

    [1]+  Stopped                 top

The message above says that the process that was stopped is named "top". What it means is that the process still exists, but is in an suspended state where it is not actively doing anything. If you try to exit your shell session, you will get a message saying something like zsh: you have suspended jobs. and you will not be able to log out.

The easiest way to restart after this is to type the command fg:

    $ fg

That will start the last stopped program. You can optionally supply a name to fg. We stopped "top" above. We can restart it like this:

    $ fg top

That will restart "top" even if it wasn't the last process stopped. <!--break--> While this sort of thing is usually learned the hard way -- by accidentally stopping a task -- it can actually be very useful. Say you have a long running task, and you want to suspend it for a bit to free up system resources. You can easily use the stop command or CTRL-z to suspend the task. And then you can use fg at a later time to resume the task right where it left off.

If you would rather just get rid of the process, rather than restarting, you can use ps to find the process ID of the stopped process, and then use kill to kill the process, or you can use killall to kill any processes with a given name. killall top will terminate all top processes on your system (or at least all that the current user has permission to terminate).