Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I resume a stopped job in Linux? I was using emacs and accidentally hit ctrl-z which blasted me back to the console. I can see it when I type 'jobs'

[*****]$ jobs
[1]+  Stopped                 emacs test_queue.cpp
share|improve this question

migrated from stackoverflow.com Apr 8 '11 at 10:42

This question came from our site for professional and enthusiast programmers.

4 Answers 4

up vote 117 down vote accepted

The command fg is what you want to use. You can also give it a job number if there are more than one stopped jobs.

share|improve this answer
12  
for reference, fg is "foreground". You can also continue the job in the background with "bg". –  Sirex Apr 8 '11 at 11:05

The general job control commands in Linux are:

  • jobs - list the current jobs
  • fg - resume the job that's next in the queue
  • fg %[number] - resume job [number]
  • bg - Push the next job in the queue into the background
  • bg %[number] - Push the job [number] into the background
  • kill %[number] - Kill the job numbered [number]
  • kill -[signal] %[number] - Send the signal [signal] to job number [number]
  • disown %[number] - disown the process(no more terminal will be owner), so command will be alive even after closing the terminal.

That's pretty much all of them. Note the % infront of the job number in the commands - this is what tells kill you're talking about jobs and not processes.

share|improve this answer
8  
I avoid "kill %1" because mistyping it as "kill 1" is really really bad :) –  barrycarter Apr 8 '11 at 14:05
3  
@barrycarter That's very true. I usually do an fg and a Ctrl-C ;) –  Majenko Apr 8 '11 at 14:08
2  
@barry: Which is why init in Upstart ignores SIG{TERM,KILL} by default. –  Hello71 Apr 19 '11 at 2:26
2  
And, of course, "never run as root" ;) –  barrycarter Apr 19 '11 at 3:04

You can also type %<process_name>; i.e., you hit Ctrl-Z in emacs, then you can type %emacs in the console and bring it back to the foreground.

share|improve this answer
    
+1, most useful answer. :) –  dmvianna Oct 21 '13 at 1:10

Just to add to the other answers, bash lets you skip the fg if you specify a job number.

For example, these are equivalent and resume the latest job:

%
%%
fg
fg %

These resume job #4:

%4
fg 4
share|improve this answer
    
While this is kind of cool, I still find it easier to type fg than %. –  rr- Oct 10 at 17:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.