Every time you execute a command with bash a job number is allocated to it. For the purposes of this allocation, multiple commands connected together in a pipeline all count as one job which will share a single job number. The shell uses these job numbers as the basis for its job control.
Job control allows you to suspend and subsequently resume the execution of processes at a later time. The shell maintains a list of currently executing jobs which can be displayed with the jobs command. In order to suspend the current foreground job you just press the key sequence Ctrl-z on the keyboard. When you do this, the job will stop running and a shell prompt will be returned, as in the following example:
$ cat >text.file Ctrl-z [1]+ Stopped cat >text.file $ jobs [1]+ Stopped cat >text.file
The Ctrl-z in the above command sequence indicates that you should press Ctrl-z at this point, which will suspend the currently executing cat command. The use of the jobs command then shows this job in the shell's list along with its job number and its current status.
When you come to resume execution of this process, you have two choices: you can either start it back in the foreground with the fg command, in which case it will continue from where it left off, or you can push it into the background with the bg command, in which case it will run as though you had initially run the command with an & operator on the end of the line.
In this particular case, you should remember that the cat command has been started in a mode where it is taking its input from the keyboard. This means that if you resume the command in the background it will immediately perform an illegal read from the keyboard and be suspended again, automatically this time, by the system:
$ bg [1]+ cat >text.file & $ jobs [1]+ Stopped (tty input) cat >text.file
The fg and bg commands operate, by default, on the most recently stopped job. When you use the jobs command, this default job will be identified by the + symbol immediately following its job number in the shell's output. In general, if you want to refer to any job in the list, not just the default job, you can do this by giving its job number after a percent (%) symbol:
$ fg %1 cat >text.file
This fg command will restart the cat job back in the foreground so that any subsequent keyboard input (up to Ctrl-d) will be written to the file text.file.
Rather than resume a stopped job, you may just wish to terminate the job altogether. This can be done with the kill command:
$ cat >text.file Ctrl-z [1]+ Stopped cat >text.file $ jobs [1]+ Stopped cat >text.file $ kill %1 [1]+ Terminated cat >text.file
If you try to logout of the system while you have any stopped jobs, you will receive a warning error message and the command will fail:
$ cat >text.file Ctrl-z $ logout There are stopped jobs.
At this point you can either deal with the stopped jobs or, if you logout again immediately, the jobs will automatically be terminated and the logout will be successful.