How can I resume a stopped job in Linux?
Solution 1
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.
Solution 2
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.
Solution 3
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.
Solution 4
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
Solution 5
If you didn't launch it from current terminal, use ps aux | grep <process name>
to find the process number (pid), then resume it with:
kill -SIGCONT <pid>
(Despite the name, kill
is simply a tool to send a signal to the process, allowing processes to communicate with each other. A "kill signal" is only one of many standard signals.)
Bonus tip: wrap the first character of the process name with []
to prevent the grep
command itself appearing in the results. e.g. to find emacs
process, use ps aux | grep [e]macs
Related videos on Youtube
Bobby
Updated on September 18, 2022Comments
-
Bobby almost 2 years
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
-
icc97 almost 6 yearsThis is actually a fairly normal work flow for Vim, if you want to keep you commands in your bash history, then you hit
Ctrl-z
type your commands and then resume. Obviously you can run commands without leaving Vim via the:!
ed command
-
-
Sirex about 13 yearsfor reference, fg is "foreground". You can also continue the job in the background with "bg".
-
Jonathan Perrodin about 13 yearsI avoid "kill %1" because mistyping it as "kill 1" is really really bad :)
-
FJ de Brienne about 13 years@barrycarter That's very true. I usually do an
fg
and aCtrl-C
;) -
JJ_Australia about 13 years@barry: Which is why init in Upstart ignores SIG{TERM,KILL} by default.
-
rr- over 9 yearsWhile this is kind of cool, I still find it easier to type
fg
than%
. -
Gauthier about 9 years
%
is awesome, thanks! As a touch-typist, I findfg
very irritating (same finger). But then, so iscd
. -
ZAD-Man over 8 yearsVery good to know
-
Wildcard almost 8 yearsAnd you can start it in the background with either
bg %
or just% &
. -
mabraham over 6 yearsThis also works if you disown a stopped process
-
Ciprian Tomoiagă over 5 yearscan you also get access to its input/output as it happens when you say
fg
? -
thomp45793 over 5 yearsThis is a much more flexible approach than working with job number. Thumbs up.
-
Lafi about 5 yearsin my case when i tried to use fg i see the stopped process appears and disappears quickly and just <fg %> succeeded to restore it.
-
Talespin_Kit over 4 yearsWhy use "%" character. Is it required to be prepended before the job number or Is it a unix convention to specify the int type ?
-
FJ de Brienne over 4 years@Talespin_Kit I have no idea why the commands require the % character. It was a design choice by the first person to implement the commands, either working at AT&T or one of the Berkeley BSD programmers many decades ago.
-
Petr Vepřek over 3 yearsTo the list of commands, you can also add
nohup
.