Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Project 8-5 Sometimes, your system might respond slowly or seem to have delays. In these conditions, it is useful to employ the top command to

Project 8-5 Sometimes, your system might respond slowly or seem to have delays. In these conditions, it is useful to employ the top command to monitor CPU use by processes and other system information, as you learn in this project. To use the top utility: 1. Display the CPU activity by typing top and then pressing Enter. Your screen should look similar to Figure 8-12. (Dont forget that this display changes while on screen.) 2. The processes are shown in the order of the amount of CPU time they use. After looking at the display for a short time, press q to exit from the top utility. 3. Run the top utility again. Notice the far-left column of information labeled PID. This column lists the process id of each process shown. Notice the PID of the top command. (In Figure 8-12, the top commands PID is 26214. Yours is probably different.) Figure 8-11 Using the find command to delete garbage files 440 Chapter 8 Exploring the UNIX/Linux Utilities 4. Press k to initiate the kill command. The top utility asks you to enter the PID to kill. Enter the PID of the top command. Press Enter to kill the process. (You might have to press Enter a second time to return to a command prompt.) Type clear and press Enter (you might have to execute clear more than once) to clear the lines from the screen. The top utility is no longer running. 5. Run the top utility in secure mode by typing top -s and pressing Enter. 6. Press k to initiate the kill command. Because top is running in secure mode, it displays the message Unavailable in secure mode, as shown in Figure 8-13. 7. Press q to exit the top utility. 8. Type clear and press Enter to clear the screen. Figure 8-12 Sample top display Hands-On Projects 441 8 Project 8-6 Plan to periodically monitor memory use in your computer, particularly if the computer seems to run slowly when you use specific programs. In this project, you use the free command to monitor memory. To use the free command: 1. Type free and press Enter. The command displays the amount of total, used, and free memory. It also displays the amount of shared memory, buffer memory, and cached memory. In addition, the amount of total, used, and free swap memory is shown. By default, all amounts are shown in kilobytes. 2. Type free -m and press Enter to see the free commands output in megabytes. 3. Type free -t and press Enter to see memory use totals. (See Figure 8-14.) Figure 8-13 Running top in secure mode so the k command cannot be used 442 Chapter 8 Exploring the UNIX/Linux Utilities Project 8-7 There are times when you might want to send the results of the top and free utilities to a computer support person for help. In this project, you save the results from these utilities to different files and then print the files. To save and print the displays generated by the top and free utilities: 1. Redirect the output of the top utility to a file in your current directory by typing top > topdata and then pressing Enter. 2. Wait about 10 seconds, and then press q to exit the top utility. Type more topdata and press Enter to confirm you have written the information to the topdata file.To see additional lines in the display, you may need to repeatedly press Enter. Type q to exit the more display of the file contents. 3. Redirect the output of the free utility to a file in your current directory by typing free > freedata and then pressing Enter. Type more freedata and press Enter to verify the contents of the freedata file. 4. Print the information you have saved for the computer support specialist by typing lpr topdata, pressing Enter, typing lpr freedata, and then pressing Enter again. 5. Type clear and press Enter to clear the screen. Figure 8-14 Displaying memory use using different free command options Hands-On Projects 443 8 Project 8-8 In UNIX/Linux, you can run programs in the background. In this project, you practice running the top program in the background. To run a program in the background: 1. Experiment with running a program in the background by running the top program in the background. Type top& and press Enter. After you enter the command, the system reports the process id or PID (id that identifies the process) used by the program that you started in the background, such as 26851 in Figure 8-15. The top utility is running, but because it runs in the background, you see no other output. 2. Continue to run the top utility in the background. Project 8-9 In this project, you learn how to use the ps command to view processes on your system. To use the ps command: 1. Type ps and press Enter. The output of the ps command includes this information about each process you are running: PID Name of the terminal or station where the process started Figure 8-15 Starting the top utility to run in the background 444 Chapter 8 Exploring the UNIX/Linux Utilities Amount of time the process has been running Name of the process Notice that the top utility might still be running in the background, or you might see a message at the end of the ps display that top has stopped running. 2. To see a list of all processes running on the system, type ps -A | more, and press Enter. 3. Press the spacebar until the command finishes its output. 4. Notice that with the command options youve used so far, it is difficult to tell the status of a process, such as whether or not it has finished. Type ps l (that is, a lowercase letter l and not a one), and press Enter to see the long display. The WCHAN column shows the status of a process, such as finish. 5. Now consider that you want to know who is running a particular process by user name. Type ps -A u | more and press Enter. (See Figure 8-16, which shows information in the middle of the listing.) Press the spacebar to scroll through the listing. Notice that many processes are being run by root as well as by your account. Project 8-10 Sometimes, you need to stop a process, such as one running in the background or one that you no longer want to use. In this project, you use the kill command to stop a process. To stop a process using the kill command: 1. In this step, you terminate the top utility that you started in Hands-On Project 8-8 and that might still be running in the background. (If you received a message that it Figure 8-16 Using ps to view user information for all processes Hands-On Projects 445 8 stopped, continue anyway for practice or restart the utility by typing top& and pressing Enter.) Type ps and press Enter. Look at the list of processes to find the top utilitys PID. 2. Type one of these commands (both perform the same operation): kill and press Enter, or kill %top and press Enter. 3. Type ps l and press Enter to see a list of the processes and to check the status (look under the WCHAN column) of the top process. Project 8-11 If you often work with plain-text documents,it is helpful to know about the ispell command for spell checking. You practice using ispell in this project. To use ispell: 1. Use the vi or Emacs editor to create a file, and name it document1. 2. Enter the following text, with misspellings: This is a document that describes our newest and fastest machineery. Take the time to lern how to use each piece of equipment. 3. Save the file and exit the editor. 4. Scan the file for spelling errors by typing ispell document1 and then pressing Enter. 5. To correct the word machineery, look at the options at the bottom of the screen, and find the one that says machinery, which is number 1 in Figure 8-17. Type the number of that option to correct the misspelling, or you can select the r (Replace ) option, retype the word after the With: prompt, and press Enter. Notice that the word is then corrected in the text. 6. On the next screen, the next misspelled word,lern, is highlighted. Find the correct spelling in the list at the bottom of the screen and enter the number that represents the correctly spelled word. 7. The program exits and returns you to the command line. Type cat document1 and press Enter. The misspelled words have been corrected. 446 Chapter 8 Exploring the UNIX/Linux Utilities Project 8-12 In this project, you create two files and use the cmp command to compare the differences. To compare two files with the cmp command: 1. Use the vi or Emacs editor to create the file file1, containing this text: This is file 1. It is a practice file. It belongs to me. 2. Save the file and exit the editor. 3. Use the editor to create the file file2, containing the text: This is file 2. It is a practice file. It belongs to you. 4. Save the file and exit the editor. 5. At the command line, type cmp file1 file2, and press Enter. Your screen looks similar to the following: [mpalmer@localhost ~]$ cmp file1 file2 file1 file2 differ: byte 14, line 1 6. This result means that the two files differ, with the first point of difference at the 14th character in both files. 7. Type clear and press Enter to clear the screen for the next project. Figure 8-17 Spell checking document1 Hands-On Projects 447 8 Project 8-13 You can use the groff utility to create your own man pages to document applications that you create. In this project, you create a man page for the phmenu application you finished in Chapter 7. To write and format a man page: 1. Verify that you are in your ~/source directory. Recall that the ~ indicates your home directory. 2. Use the vi or Emacs editor to create the file phmenu.1. Type the following text into the file: .TH PHMENU 1 "November 2008" "phmenu Version 1.01" .SH NAME phmenu \- Menu for Dominion Employee Telephone Listings .SH SYNOPSIS \fB phmenu\fP .SH DESCRIPTION \fP Menu for maintaining employees' phones and job titles\fP. \fP Record includes phone number, name, dept, and date-hired\fP. .SS Options .TP \fB -v \fIView Phone List\fR Display unformatted phone records. .TP \fB -p \fIPrint Phone List\fR Corporate Phones report sorted by Employee Name. .TP \fB -a \fIAdd Phone to List\fR Add new phone record. .TP \fB -s \fISearch for Employee Phones\fR Enter Name to search and retrieve phone record. .TP \fB -d \fIDelete Phone\fR Remove phone record. .SH FILES .TP \fC/home/source/corp_phones\fR 3. Save the file and exit the editor. 4. Test the man page by typing groff -Tascii -man phmenu.1 | more and then pressing Enter. Your screen should appear similar to Figure 8-18. If you find any formatting discrepancies, check the dot commands and any embedded font changes against the code you typed in Step 2. 448 Chapter 8 Exploring the UNIX/Linux Utilities 5. Press q to exi

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro SQL Server Administration

Authors: Peter Carter

1st Edition

1484207106, 9781484207109

Students also viewed these Databases questions

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago