Return
|
You want to halt and restart processes, run more than one process at a time interactively, or let a process you started interactively continue to run after you log off.
Use Korn shell control key sequences and commands to interactively control processes, much like with DCL.
Use the following control key sequences for processes you have started interactively:
| DCL | Ksh | Action |
|---|---|---|
C-c or C-y |
C-c |
Stop current command. |
C-z |
C-d |
End-of-file (or logout!) |
C-s/C-q |
C-s/C-q |
Start and stop display. |
C-c ... continue |
C-z ... fg |
Suspend current process. |
C-t |
-- |
Report status of current process. |
C-o |
-- |
Throw away current output, display next prompt. |
Unfortunately there are no direct analogs to VMS's very useful
C-t and C-o commands.
In VMS C-z is the special character that signals
END-OF-FILE and as such is recognized by most VMS applications as
either an indication to stop reading data and proceed, or in many
cases, perform a normal exit. But at the DCL command line,
C-z has no real effect. Likewise in Unix
C-d is the END-OF-FILE character and is recognized as
such by virtually all Unix applications -- and the shell! Thus
typing C-d at the shell prompt exits that shell, and
if that happens to be the login shell, logs you out! Set the
shell option:
set -o ignoreeof;
to turn this off. (See 1.06 for how to
make this setting everytime you login.)
Also illustrated in the table above is the fact that in DCL you can
halt a program using C-c and then restart it using the
continue command. But in VMS, this only works if you
do not run another intervening image. Thus you can only invoke DCL
commands that do not call an external program, otherwise the
interrupted program's image is purged from memory and cannot be
continued. In contrast, with Unix the suspend program can be left
in a suspended state so long as you remain in the
shell1 that was used to start it. Running
other programs, or even starting up a new instance of the same
program, will not force the suspended job out of memory.
Using shell's interactive job control, you can suspend a process,
make a process run in the 'background' (bg), and
bring a background or suspended process into the foreground
(fg) -- i.e. running connected to your terminal.
Here is a simple example of suspending a process and bringing it back into the foreground:
unix> emacs myprog.pl
... enter program code ...
... force editor to save edits to file ...
... press C-z
[1] + Stopped emacs myprog.pl
unix> chmod +x myprog.pl
unix> ./myprog.pl
Name "main::x" used only once: possible typo at ./myprog.pl line 3.
Name "main::y" used only once: possible typo at ./myprog.pl line 3.
unix> fg
... screen clears and the editor resumes at the last location.
In a similar fashion, you can alternate between two programs.
unix> emacs somefile.txt
... enter text ...
... press C-z
[1] + Stopped emacs somefile.txt
unix> pine
... read and send mail ...
... press C-z
[2] + Stopped(SIGSTOP) pine
unix> fg %1
... screen clears and the editor resumes at the last location.
... exit from editor (not C-z).
unix> fg
... pine is the most recently suspended job, so it is restarted.
... normal exit from pine (not C-z).
unix> fg
ksh: fg: no such job
unix>
Processes can be made to run in the background. In this mode,
the process will run until completion or until it requires
input from the terminal. Here is an example of immediately
running a command in the background by ending the command
using the ampersand (&) character:
unix> sort big-file-1 big-file-2 >bigger-file&
[1] 1850063
unix> pine
... read my mail ...
... exit or suspend pine
[1] + Done sort big-file-1 big-file-2 >bigger-file&
unix>
A common situation is wanting to throw a job into the background
after it has already been started. Do this by suspending the
job and then using the bg command:
unix> ./slow-job
processed 1000 lines
... suspend process by pressing C-z
[1] + Stopped ./slow-job
unix> bg
unix> pine
... read my mail ...
processed 2000 lines
... refresh my screen! ...
processed 3000 lines
... refresh my screen! ...
... exit from pine
[1] + Done ./slow-job
unix>
When you try to leave the shell while jobs are stopped or running,
you are warned that you have stopped jobs. You can use the
jobs command to see what they are. If you do this
or immediately try to exit again, the shell does not warn you a
second time. With the Korn shell, running and stopped jobs
are terminated. With the BASH shell, stopped jobs are terminated,
but running jobs continue so long as they do not require terminal
input. Any output to the terminal will be lost, but any other
output is completed.
unix> ./slow-job >slow-job.out
./slow-job: processed 1000 lines
[1] + Stopped ./slow-job >slow-job.out
unix> bg
[1] ./slow-job >slow-job.out&
./slow-job: processed 2000 lines
unix> exit
You have running jobs
unix> exit
... logged off the system.
Finally, it is possible to run more than one shell from your single
terminal or terminal window. This can be particularly handy when
using the su command to 'login' on a different
account, and then switch back and forth between the two
sessions. The shell command suspend is used to
suspend the current shell:
unix> whoami wfc unix> su xyz Password: xxxxxxx jupiter_xyz> whoami xyz jupiter_xyz> suspend [1] + Stopped(SIGSTOP) su xyz unix> whoami wfc unix>
Note that the BASH shell has some additional features for
job control not available in the Korn shell.
For more information type man bash at the
shell prompt and/or see the
BASH
reference manual.
1.1 - Command Line Editing;
1.6 - Environment Initialization;
Chapter 3 of Unix for OpenVMS Users
.
(1) If you try to exit the shell or log out with suspended
jobs, you will initially be prevented and the warning message
You have stopped jobs will be displayed. Typing
C-d again (i.e. twice in a row)
will force shell exit and loss of the suspended job(s).
  Return
|
|
Colophon: |
|
||||
|
This page maintained by: Bill.Costa@unh.edu of the Enterprise Computing Group in the dept of Computing & Information Sevices at the University of New Hampshire |
|
||||