353
117
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
353
117
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
404
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.
59for reference, fg is "foreground". You can also continue the job in the background with "bg". – Sirex – 2011-04-08T11:05:39.170
268
The general job control commands in Linux are:
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.
Why use "%" character. Is it required to be prepended before the job number or Is it a unix convention to specify the int type ? – Talespin_Kit – 2020-02-28T05:03:28.540
@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. – Majenko – 2020-02-28T11:00:07.043
33I avoid "kill %1" because mistyping it as "kill 1" is really really bad :) – barrycarter – 2011-04-08T14:05:12.640
5@barrycarter That's very true. I usually do an fg
and a Ctrl-C
;) – Majenko – 2011-04-08T14:08:22.933
6@barry: Which is why init in Upstart ignores SIG{TERM,KILL} by default. – Hello71 – 2011-04-19T02:26:21.473
7And, of course, "never run as root" ;) – barrycarter – 2011-04-19T03:04:52.683
48
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.
Very good to know – ZAD-Man – 2015-10-22T21:42:04.103
34
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
2While this is kind of cool, I still find it easier to type fg
than %
. – rr- – 2014-10-10T17:10:13.833
3%
is awesome, thanks! As a touch-typist, I find fg
very irritating (same finger). But then, so is cd
. – Gauthier – 2015-04-15T13:45:38.707
And you can start it in the background with either bg %
or just % &
. – Wildcard – 2016-08-16T18:43:04.117
in my case when i tried to use fg i see the stopped process appears and disappears quickly and just <fg %> succeeded to restore it. – Lefi Tarik – 2019-06-25T12:54:43.753
23
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
3This also works if you disown a stopped process – mabraham – 2017-12-06T01:21:39.877
can you also get access to its input/output as it happens when you say fg
? – Ciprian Tomoiagă – 2018-10-02T09:39:01.013
This is a much more flexible approach than working with job number. Thumbs up. – thomp45793 – 2019-02-14T22:55:00.087
This 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 – icc97 – 2018-07-11T02:32:22.273