Linux Bible. Christopher Negus

Чтение книги онлайн.

Читать онлайн книгу Linux Bible - Christopher Negus страница 63

Linux Bible - Christopher Negus

Скачать книгу

in various ways by right-clicking a process name and selecting from the menu that appears (see Figure 6.3 for an example).

      Here are some of the things you can do to a process from the menu you clicked:

       Stop: Pauses the process so that no processing occurs until you select Continue Process. (This is the same as pressing Ctrl+Z on a process from the shell.)

       Continue: Continues running a paused process.

       End: Sends a Terminate signal (15) to a process. In most cases, this terminates the process cleanly.

       Kill: Sends a Kill signal (9) to a process. This should kill a process immediately, regardless of whether it can be done cleanly.FIGURE 6.3 Renice, kill, or pause a process from the System Monitor window.

       Change Priority: Presents a list of priorities from Very Low to Very High. Select Custom to see a slider bar from which you can renice a process. Normal priority is 0. To get better processor priority, use a negative number from –1 to –20. To have a lower processor priority, use a positive number (0 to 19). Only the root user can assign negative priorities, so when prompted you need to provide the root password to set a negative nice value.

       Memory Maps: Lets you view the system memory map to see which libraries and other components are being held in memory for the process.

       Open Files: Lets you view which files are currently being held open by the process.

       Properties: Lets you see other settings associated with the process (such as security context, memory usage, and CPU use percentages).

      You can display running processes associated with users other than yourself. To do that, highlight any process in the display (just click it). Then, from the menu button (the button with three bars on it), select All Processes. You can modify processes you don't own only if you are the root user or if you can provide the root password when prompted after you try to change a process. Sometimes, you won't have the luxury of working with a graphical interface. To change processes without a graphical interface, you can use a set of commands and keystrokes to change, pause, or kill running processes. Some of those are described next.

      Although the bash shell doesn't include a GUI for running many programs at once, it does let you move active programs between the background and foreground. In this way, you can have lots of stuff running and selectively choose the one you want to deal with at the moment.

      You can place an active program in the background in several ways. One is to add an ampersand (&) to the end of a command line when you first run the command. You can also use the at command to run commands in such a way that they are not connected to the shell.

      To stop a running command and put it in the background, press Ctrl+Z. After the command is stopped, you can either bring it back into the foreground to run (the fg command) or start it running in the background (the bg command). Keep in mind that any command running in the background might spew output during commands that you run subsequently from that shell. For example, if output appears from a command running in the background during a vi session, simply press Ctrl+L to redraw the screen to get rid of the output.

      TIP

      To avoid having the output appear, you should have any process running in the background send its output to a file or to null (add 2> /dev/null to the end of the command line).

      Starting background processes

      If you have programs that you want to run while you continue to work in the shell, you can place the programs in the background. To place a program in the background at the time you run the program, type an ampersand (&) at the end of the command line, like this:

       $ find /usr> /tmp/allusrfiles & [3] 15971

      This example command finds all files on your Linux system (starting from /usr), prints those filenames, and puts those names in the file /tmp/allusrfiles. The ampersand (&) runs that command line in the background. Notice that the job number, [3], and process ID number, 15971, are displayed when the command is launched. To check which commands you have running in the background, use the jobs command, as follows:

       $ jobs [1] Stopped (tty output) vi /tmp/myfile [2] Running find /usr -print > /tmp/allusrfiles & [3] Running nroff -man /usr/man2/* >/tmp/man2 & [4]- Running nroff -man /usr/man3/* >/tmp/man3 & [5]+ Stopped nroff -man /usr/man4/* >/tmp/man4

      The plus sign (+) next to number 5 shows that it was most recently placed in the background. The minus sign (-) next to number 4 shows that it was placed in the background just before the most recent background job. Because job 1 requires terminal input, it cannot run in the background. As a result, it is Stopped until it is brought to the foreground again.

      TIP

      To see the process ID for the background job, add a -l (the lowercase letter L) option to the jobs command. If you type ps, you can use the process ID to figure out which command is for a particular background job.

      Using foreground and background commands

      Continuing with the example, you can bring any of the commands on the jobs list to the foreground. For example, to edit myfile again, enter the following:

       $ fg %1

      As a result, the vi command opens again. All text is as it was when you stopped the vi job.

      CAUTION

      Before you put a text processor, word processor, or similar program in the background, make sure that you save your file. It's easy to forget that you have a program in the background, and you will lose your data if you log out or the computer reboots.

      To refer to a background job (to cancel or bring it to the foreground), use a percent sign (%) followed by the job number. You can also use the following to refer to a background job:

Скачать книгу