Use
CTRL-C
instead. It is more common to interrupt a process.
I think
this old article may explain the trouble. I don't run anything in "background" so I hope that the article explains it well enough and is still accurate.
These commands run fine for me.
Code:
sudo find / -mtime -5 # This outputs everything to the console
Code:
sudo find / -mtime -5 > /home/stan/Desktop/testfile.txt
# This saves a LARGE text file (over 10 MB) but errors still output to the console
If the OPs command is running in the background, then Ctrl+C and Ctrl+Z won’t help.
To stop a process running in the background, you have to use the kill command and send a signal.
The syntax is:
Code:
kill {options} {signal} {pid}
Where {options} are any options you might want to use.
{signal} is the signal you want to send to the application.
And {pid} is the pid of the process you want to control.
So to stop/pause the command you’d send a SIGSTOP signal (-19).
To resume a command, you’d send SIGCONT (-18).
And to kill the process entirely - you should use SIGTERM (-15), which tells the application to wrap things up and shut itself down.
This shuts processes down cleanly and prevents any loss, or corruption of data.
And if sending signal -15 fails to kill the process, the last resort is to send the SIGKILL (-9) signal, which will kill the process dead, regardless of what it’s doing. Which runs a risk of possible data loss, or corruption in any files that the process may have been writing to.
When you run a command in the background, the shell will output the pid (process ID) of the background task.
If you forget the pid, or it scrolls off the screen with any output from the command, you can use the jobs command to list any running background jobs.
E.g.
And that will show you the pid’s of all background jobs that are running in the current shell.
If the job is running in another shell, you’d need to use something like pgrep to identify the pid.
Once you have the pid of the background process, you can send a signal to stop it, like this:
Where 12345 is the pid of the process we want to stop. And hopefully, the process will stop!
To resume the process, repeat the above command and send -18 instead of -19.
Likewise, to kill the process - send -15 (or -9) as a last resort.
You can specify the signals as SIGSTOP, SIGCONT, SIGTERM, or SIGKILL, but I prefer to use their numbers, because it’s a few less characters to type! Ha ha!