I 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?
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.
- Difference between process group and job?
- What is the difference between a job and a process?
- Shell's process group ID = foreground job's process group ID?
- Who changes the foreground process group of a terminal?
- Are all of the signals sent from the terminal gets sent to the foreground process group?
- Which process group does my program belong to when started from bash?
- Can Ctrl+C send the SIGINT signal to multiple processes?
- Will a child process be in a different process group than the parent process?
- Why is SIGINT not propagated to child process when sent to its parent process?
- What is the purpose of abstractions, session, session leader and process groups?
- What is the purpose of the controlling terminal?
- Background, zombie, daemon and without ctty - are these concepts connected?
- … and many more.
prog >logfile 2>&1 &or
prog >/dev/null 2>&1 &if you don't want to see its output.