Managing your current jobs in the stack
Last revision August 9, 2004
Table of Contents: |
Several C-shell commands allow you to affect the jobs in the stack.
jobs | shows you the status of all background and suspended jobs. |
kill | will kill a suspended job. |
fg | brings a suspended job back into the foreground and re-starts it exactly where it left off. The shell goes back to a wait state. |
bg | works just like fg, except that instead of re-starting a suspended job in the foreground and making the shell wait, it restarts the job in the background, just as if you had originally ended the command input with an ampersand. You get a new shell prompt immediately. |
For example, if you needed to move a large directory with many files to the scratch disk and you started that with a mv command. But if you became impatient and needed to check something else, you could suspend it with CTRL-Z. Next, you could open an on-line manual page, and then suspend it. Finally, you could start a vi editor session and then suspended it. Running the jobs command shows these three suspended jobs in your stack:
pangea> jobs
[3] + Stopped vi processnotes
[2] - Stopped man 7 tty
[1] - Stopped mv bigdir /scr1
With no arguments, kill, fg, and bg affect the current job in the stack. The current job is the one indicated by a + sign in the output of the jobs command. In the example above, the current job is the vi job, and you can resume it (bring it back into the foreground) with the command
fg
In general, the current job will be the most recently suspended one.
To affect a suspended job that is not the current job, you give its job number to the kill, fg, or bg commands as an argument in the form %n, where n is the job number (from the output of the jobs command). In the example above,
kill %2
will kill the suspended man job without bothering to resume it.
If you try to logout from your current session when there are suspended jobs, the shell will warn you and will not immediately logout. Kill the suspended jobs first, or start them going again in the background, and then logout. In the example above, you can just push the mv job into the background and let it finish even after you have logged out, because it does not need any input or output to the terminal. You would do that with the command
bg %3
<--Previous | Overview | |