6

After pausing the process with ctrl-z, I attempted to send it to background with bg command. Unfortunately, the process isn't sent to the background, and reappear to be running foreground. Then, I do a ctrl-z again in order to pause it again. Unfortunately, the key combination is no longer responding and the process is still ongoing. To make matters worst, the command is a for loop on many items. If I hit ctrl-c, the job will resume on the next iteration, and until the last iteration.

Running on tmux inside iTerm on macOS.

2 Answers 2

15

From your description, the bg command did work, otherwise ctrl-z and ctrl-c would still work.

Just because a process is in the background doesn't mean it can't still send you outoutput. If you don't want to see that, run stty tostop and then background jobs will be stopped if they try to send output, and then you can continue them in the foreground (fg) if you want.

If you have a noisy process running in the background like this, you probably can press return a few times and see that you are still getting a shell prompt. You can remedy the situation in a few ways:

  • You can try to kill it by blindly typing a kill command.
  • You can blindly type stty tostop as suggested above.
  • You can type fg to bring it back to the foreground (hopefully you don't have more than one and get the wrong one), and then either stop it wtih ctrl-z or kill it with ctrl-c
  • If you are in a graphical environment or a terminal multiplexer (like tmux), you can open another window and try to find the offending process with ps or top and kill it from there.
1
  • 2
    kill (and bg and fg) also accept job spec, which is a % and job number. So kill %1 should kill the first background job.
    – Jan Hudec
    Commented Apr 11, 2023 at 21:39
0

The text window command "jobs" will report what jobs are stopped by cntl-Z. "fg #" and "kill #", where # is the jobs number reported by the command will bring the # selected jobs to the fg or kill the running progresses. The jobs command works in sh, csh, bash. It is better to use "fg" and quit the program than kill it.

This does not work: "more" a text file, .c, etc. While in more type the single v command to edit the text file. If the "vim" edit session is cntl-Z, the terminal will hang and the "more" command and "vim" will have to be killed from another window. Additional cntl-Z, fg, kill, ls, ps, etc commands will not work in the hung terminal.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .