In addition to the standard UNIX mechanisms for scheduling the time at which a program will be executed, the shell provides its own internal scheduling mechanisms. The sched and commands can be used to run a process at some future time.
bg
[%%job ]
Puts the specified jobs into the background. Job may be a number, a string, '', '%', '', or '-'.
Example: Suppose you're running a long job and you get bored waiting on it. You don't want to stop it because it has to be run, but you want your terminal back; therefore,
1. Use the following key sequence: To suspend the job,
<Ctrl>+Z
2. To get the command's job number, use the following command:
jobs
3. To restart the job in the background, use the following command:
bg %1
exec command
Executes the specified command in place of the current shell. Note that for any command other than another shell, this is effectively a logout.
Example: To terminate your current shell and replace it with tcsh, use
exec /bin/tcsh
fg
[%%job ]
Brings the specified jobs into the foreground. Recalls that job numbers are displayed by using the jobs command.
Example: To bring job 3 into the foreground, use
fg %3
hup
[command]
Runs the specified command in such a way that it will exit upon receiving a hangup signal. The benefit of running a command with hup is that the command will be sent a hangup signal if the parent shell exits.
Example: To run the command update_database in such a way that it will receive a hangup signal if the parent shell exits while it is running, use
hup update_database
jobs
[-l]
Lists the active jobs. The -l option includes process ids in the listing.
Example: To list the currently active jobs, together with their process id's, use
jobs -l
kill
[-signal] %%job|pid
kill-l
Sends a signal to the specified job or process, thereby killing it. Some of the more useful values for signal are
Name | Value | Effect |
KILL | 9 | Should kill any process immediately and ungracefully. |
QUIT | 2 | Tells the process to quit what it's doing and then die. |
HUP |
| Politely asks the process to tidy up and then die. |
To obtain complete listing of the symbolic names of the possible signals that can be generated with the l option, use
kill l
The possible signals are defined in /usr/include/signal.h.
Example: To forcefully demand that job 3 die immediately, use
kill -KILL %3
limit
[-h] [resource [maximum-use]]
Limits the consumption of the specified resource by the current process and each process it creates to not individually exceed maximum use. If no value for maximum use is given, it will display the current value
Resource may be one of | |
cputime | Amount of CPU time, in seconds, used by each process. |
filesize | Size of largest file that can be created. |
datasize | Maximum growth of the datastack region beyond end of program text. |
stacksize | Maximum size of the automatically extended stack region. |
coredumpsize | Size of the largest core dump. |
memoryuse | Upper limit on the amount of physical memory a process may have allocated to it. |
The maximum-use value may be given as a (floating point or integer) number followed by a scale factor. For all limits other than cputime the default scale is 'k' or 'kilobytes' (1024 bytes); a scale factor of 'm' or 'megabytes' may also be used. For cputime the default scaling is 'seconds', while 'm' for minutes or 'h' for hours, or a time of the form 'm:s' giving minutes and seconds may be used.
See also unlimit.
Example: To set an upper limit of 300 seconds of cputime for the current process (the shell) and all its child processes, use
limit cputime 300
migrate
[-site] pid|%%jobid
migrate-site
Migrates the current process by default (that is, the shell) or, more usefully, the specified process or job to the specified site.
Example:
nice [number] [command]
Set the scheduling priority of the specified command to a number in the range -19 through 20. Note that for all users other than root, this number must be higher than the current. Scheduling priority is used by the CPU to determine which process gets next use of system resources.
Example: To invoke the slowsort command with the lowest possible priority, use
nice 20 slowsort
Example: To invoke the slowsort command with the highest possible priority (root only), use
nice -19 slowsort
nohup
[command]
Runs the command in such a way that it will ignore hangup signals.
Example: To run the command bigsort in such a way that it will ignore hangup signals, use
nohup bigsort
notify
[%%job ]
Tells the shell to notify a user when the status of the specified job changes. Job numbers are obtained by means of the jobs command.
Example: To tell the shell to notify you when job 3 completes or otherwise changes status, use
notify %3
onintr
[-|label]
This command tells the shell how you want it to react to an interrupt signal. An argument of '-' tells the shell to ignore all interrupts. An argument of label will cause the shell to jump to the specified goto label upon receipt of an interrupt.
Example: To tell the shell to ignore all interrupt signals, use
onintr -
sched
sched
[]hh:Mm command
sched -n
With no arguments, sched displays the scheduled event list. The second form adds the specified command to the scheduled event list at the specified hour and minute. Similar to the at command found on most UNIX systems, but has access to shell variables and other structures.
Example: To schedule the slowsort process to begin running at midnight, use
sched 00:00 slowsort
stop %%job|pid
Stops the specified jobs or processes which are executing in the background. Job numbers are obtained via the jobs command.
Example: To suspend the execution of job 3, use
stop %3
suspend
Causes the shell to stop, with an effect similar to the stop signal.
Example: To halt the execution of job 3, use
suspend 3
time
[command]
Executes the specified command and displays a summary of how long it took to run. Without arguments, time displays a time summary of the current shell and any children it may have. Useful in performance metrics.
Example: To execute the command slowsort and display a listing of how long it took to run, use
time slowsort
unlimit
[-h] [resource]
Removes any limitation on usage of the specified resource. With no arguments, all resource usage limits are removed.
Example: To remove any set limits on the cputime resource, use
unlimit cputime
wait
Tells the shell to wait for all background jobs.
Example: This command has no options or arguments. To tell the shell to wait for all background jobs, type
wait