Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I put a process to background after its execution with broken CTRL+Z?

The question is special because some keys, such as CTRL+Z, stopped working.

I tried to put the process to background by typing in the order:

  1. find /
  2. CTRL+Z
  3. bg

However, I can still see the stdout. The only difference to only doing the first step is that the command CTRL+Z does not work anymore. It is rather nasty when I have unsaved jobs and my harddrive is over 100GB. So

how can I put the process to background?

[Details]

I am using the fourth version of Bash on Mac.

[Crux Reply by Nicholas Riley]

The problem is really that I do not understand the "ramifications" of running process background. I cannot understand why the commnands, such as CTRL+Z, do not work to background processes. I was still able to kill the process in another shell with the command:

ps -ej | awk '! /grep/ && /find/ {print $2}' | xargs kill -9
like image 737
Léo Léopold Hertz 준영 Avatar asked Apr 28 '09 03:04

Léo Léopold Hertz 준영


Video Answer


1 Answers

^Z isn't working because the frontmost job is now the shell, and shells don't usually respond to SIGTSTP. (If you do really want to suspend a non-login shell, suspend usually works.)

The problem seems to be you misunderstand the ramifications of a job being in the background. Redirecting the job's standard output is unrelated.

In fact, it's unclear what you want to do. If you just want to stop find from running, then fg it and use ^C or ^\ (which by default send SIGINT and SIGQUIT respectively).

If you want to keep find running but suppress its further output, then the easiest solution I can think of is to use bg ; disown ; exit. That will stop the shell from killing its child process (find) and exit the shell; assuming it's at the top level of the Terminal window, you'll see a bit more output and find will keep running (but you'll have no way to interact with it).

like image 50
Nicholas Riley Avatar answered Sep 27 '22 17:09

Nicholas Riley