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
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.
fg 1
doesn't work, the syntax is fg %1
Commented
May 4, 2023 at 7:50
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.
fg
and a Ctrl-C
;)
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.
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
fg
than %
.
%
is awesome, thanks! As a touch-typist, I find fg
very irritating (same finger). But then, so is cd
.
bg %
or just % &
.
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
fg
?
Commented
Oct 2, 2018 at 9:39
For anybody who wants to continue all suspended processes.
I don't know how but I achieved several times to completely lock my screen. When I check the processes there are dozens that are suspended. So I continued all processes to unlock my screen.
Switch to text console with Ctrl-Alt-F3
or similar. Log in, then issue:
ps ax|grep " T"| awk '{print $1}' |grep -v PID | xargs echo kill -SIGCONT
ps
lists all processesgrep
finds mostly only suspended processes (dirty hack, improve?)awk
fetches only first column, PIDgrep
removes header "PID"xargs
executes a command on the input givenecho
shows command instead of executingkill -SIGCONT
sends signal to continue the processOutput is something like this:
kill -SIGCONT 214191 334813
Either remove echo
, cut & paste or pipe the output through bash
to actually execute it.
Ctrl-z
type your commands and then resume. Obviously you can run commands without leaving Vim via the:!
ed command