Answer the question
In order to leave comments, you need to log in
How to run an already stopped program in the background without switching to foreground?
I run:
1. ping www.google.com
2. Ctrl+Z stop the process and exit it
The process hangs as Stopped
3. I prescribe bg in order to start the stopped process in the background and not go into the process itself.
And at the 3rd stage, it throws me into the process itself, where I see the execution of the ping command, while Ctrl + Z / Ctrl + C may not work and you need to press 10.
It turns out that bg does the same thing as fg, but it seems to freeze and does not react to stopping or interruption
How to correctly run an already stopped command in the background?
The fact that you can immediately run a command in the background with >/dev/null 2>&1 & I know, but I wonder how it should work without it and whether it should.
Ubuntu Linux Version 20.04.2
Answer the question
In order to leave comments, you need to log in
> And at the 3rd stage, it throws me into the process itself, where I see the execution of the ping command, while Ctrl + Z / Ctrl + C may not work
This is the output of the process, the process itself continues to run in the background and you can start another process if you want.
In order not to see the ping output, the easiest thing is to redirect the output somewhere.
You need to understand two points
of the jobs command, bg and fg are internal commands of the shell, and work with the child processes of this particular shell.
If you paused a child process (Ctrl-Z) or launched it directly into the background (ping google.com &), then with the fg command you bring it to the foreground. It's like in Windows you took and put the focus on the notepad window with the mouse, after which you will write in this notepad by pressing the keys.
And if you paused the process with Ctrl-Z and resumed it with bg, it will continue in the background with your shell in the foreground - you can write other commands. It's like clicking the mouse in Windows on the desktop next to the notepad, and therefore by pressing the keys you will write not in the notepad but on the desktop (the arrows run over the icons, some hotkeys can work, Enter will launch the current icon)
To understand, practice So:
sleep 100
CTRL-Z
jobs
bg 1
echo I am still in shell
fg 1
CTRL+C
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question