How to send a process to background and foreground?
fg
is the correct command to foreground a job, but if there is more than one job running you should specify the job number. If you type only fg
, the last backgrounded job (considered the current job by the shell) will be brought to foreground.
Get the current jobs:
$ jobs
[1]+ ping google.com &
Foreground the job by specifying the number:
fg %1
The command may be broken up by output from the running process, but it will still work, you can ignore the interruption.
Then hit ctrl+c to interrupt and stop the process
As mentioned in a comment, you can also send signals by job number, for example kill %1
For completeness, if you didn't use the &
at the time of calling the process, you can send it to the background by first freezing with ctrl+z and then typing bg