0

enter image description hereI suspend a running process by ctrl+Z and the bg to place process in the background but the process still running in the foreground so I cannot use the command line. How can I put the process completely in the background so I can use the command line?

  • Hello and welcome to the U&L stack exchange site! Please review the Help Center to get information on how to best post to this site. To get to your question, please edit your post to include additional context. What terminal emulator are you using? What operating system are you using? Thank you! – kemotep Feb 15 at 21:46
  • An example showing this behaviour would be nice to see. – Kusalananda Feb 15 at 22:04
  • 1
    even if it's put in background, a process can still write stuff to your terminal. there are various hacky way to force redirect its output somewhere else (maybe someone can prove wrong and show some nice standard way of doing that) -- but the moral is that you should start your background program as prog >logfile 2>&1 & or prog >/dev/null 2>&1 & if you don't want to see its output. – mosvy Feb 15 at 23:16
  • Please edit your question to answer the questions in the comments. This question is marked as a duplicate, and will close soo. If you re-edit your question it will be reviewed again. – X Tian Feb 16 at 11:53
2

You have the wrong idea about what foreground and background mean when it comes to terminal job control. They are not determined by whether you can see output.

A terminal device (more specifically, the line discipline) has a foreground process group ID associated with it. This determines what process group the line discipline sends signals to, when it is in canonical mode and receives one of the special characters that maps to a signal (which is information that is also held in the line discipline).

Job-control shells allocate process groups to the processes that comprise shell jobs, and switch the terminal device's foreground process group among these process groups, and its own process group, in order to perform job control.

This does not by default affect output, to the terminal from those processes. There is only one circumstance where this affects output, which is when you have turned the tostop flag on in the line discipline (with stty or some such command). This flag being on is not the default. (There are just two exceptions that I know of: one can set default initial settings on some operating systems, but only for real terminals, e.g. sio devices on FreeBSD; and my vc-reset-tty tool sets this flag on when resetting to "sane" state.)

As such, if you have shell jobs running that generate output, that output will be intermingled with the shell's output.

The alternative of turning tostop on will not help you here. You have a shell job that generates output continually. It is apparently outputting an interactive progress display. Terminal job control does not marry well to continually interactive programs. (Text editors like vi and text file viewers like more, in contrast, are not continually interactive.) Your choices are tostop off and the progress display mixing with that of other processes, or tostop on and the progress display causing the program to be halted at each progress update.

Or, on the gripping hand, using two terminals.

Further reading

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.