`UNIX variants—
`including Linux,
`Solaris, HP-UX,
`AIX, FreeBSD,
`
`
`
`Second Edition
`
`Complete
`Reference
`
`and Mac OS X
`NIX ff
` ne must-have book on UNIX for
`
`MhNe
`
`|
`-_—t
`
`iel
`Bilaiihii
`
`1ers through experienced users
`
`p, administer, and manage UNIX onall
`f computers
`
`mplete details on GNOME, KDE, and CDE
`programming, Perl and Python, and many
`‘ner UNIX tools and developmentresources
`
`Kenneth Rosen
`Douglas Host
`Rachel Klee
`James Farber
`Richard Rosinski
`era Osborne
`
`1
`
`SAMSUNG 1020
`
`
`
`The Complete Reference,
`Second Edition
`
`Seoul Singapore Sydney Toronto
`
`Kenneth H. Rosen
`Douglas A. Host
`Rachel Klee
`James Farber
`Richard Rosinksi
`
`Nf
`TTY
`Hill
`
`NewYork Chicago San Francisco
`Lisbon London Madrid Mexico City
`Milan New Delhi San Juan
`
`2
`
`
`
`
`
`3
`
`
`
`:
`
`Chapter 4:
`
`The Command Shell
`
`107
`
`mmandin the background onbig_file, sends its output to output, and
`troff co
`essages. In csh or tesh, this would look like
`ne i
`discards error m
`$
`(eroLt bigfile > output)
`>& /dev/null &
`Logging Off with Active Jobs
`acommandthat takes a very long time, you may want tolog out before it finishes.
`]f you run
`if you log out while a backgroundjob is running it will be terminated. However,
`Ordinarily,
`e nohup (no hang up) commandto runajob that will continue running even if
`ou can use th
`you log out. For example,
`ind
`-name "lost_file" -print > lostfound 2>&1 &
`s nohup find
`/
`in the Bourne-compatible shells, or
`
`
`
`$ nohup find / -name "lost_file" -print >& lostfound &
`in the C shells, allow find to continue even after you quit. This commandstarts looking in
`the root directoryof thefile system for any files named lost_file. Any pathnamesthat are
`found are putin the file named Jostfound, along with any error messages. The whole thing is
`run in the background,to allow you to enter other commandsorlog out.
`When you use nohup, you should be sure to redirect both standard output and standard
`errorto files, so that when youlog back in you can find out what happened.If you do not
`specify outputfiles, nohup automatically sends commandoutput, including standard error,
`to the file nohup.out.
`saree
`cmseAOESOPHOn WENOMMEERPSREYNAUDAPR
`
`Job Control
`Because the UNIX System providesthe capability to run commandsin the background, you
`sometimes have two or more commandsrunningat once. There is always one job in the
`foreground. This may bethe shell, whenit is prompting you for input, or it may be any other
`commandto which your keyboard inputis connected, such asa text editor. In addition, there
`may be several jobs running in the backgroundat any given time.
`Job control is a crucial feature of the modern UNIX shells that wasfirst introduced in csh
`and is also found in tesh, ksh, and bash. The commandsandsyntax are for the most part
`identicalin all four shells. The job control commandsallow you to terminate a background
`job (kill it), suspend a background job temporarily (stop it), resume a suspended job in the
`background, move a backgroundjob to the foreground, and suspend a foregroundjob.
`The jobs commanddisplaysa list of all your jobs, such as
`
`$ jobs
`[1]
`+ Running
`find /home/jmf -print > files &
`(2)
`Stopped
`vi filesplit.tecl
`[3] -
`stopped
`grep supv *
`| awk -f fixes > data &
`Bie Output shows yourcurrent foreground andbackgroundjobs, as wellas jobs that are
`mse or suspended.In this example, there are three jobs. The numberat the beginningof
`line is thejob ID. Job 1 (the find command)is running in the background. Jobs 2 and 3
`
`
`
`4
`
`
`
`
`
`5
`
`
`
`
`
`6
`
`