[ Pobierz całość w formacie PDF ]
.o \) -xdev > deletelist.txtNote that you can also set this command to run unattended, at regular intervals, and havethe report emailed to you as an automatic reminder.See Hour 24, Scheduling, for details.If you experiment with your own combination of commands, you ll soon come up with yourown customized reports and cleanup actions.You now know how to get information aboutyour drive space.You ll also learn about managing disk space, using quotas (software limitson hard drive usage) in the Managing User Access section.For now, you ll learn how to findout more about what s going on in your computer s memory when you run Linux.Getting Memory InformationAlthough the industry trend has been to offer more hard drive space and more memory forless money, many people don t like to outlay more cash to expand their systems.The goodnews is that Linux is very efficient at using memory, because even a 16MB system providesenough room (with an equal amount of swap space) to run X11 and most programs well.Thebad news is that programs are getting larger all the time, especially with feature creep, in whichmore and more functions creep into programs.This section introduces you to some programsyou may find helpful in understanding your system s memory, and gives you some tips onconserving memory.Memory Reporting with the free Command2 0Thefree command shows breakdowns of the amounts and totals of free and used memory,including your swapfile usage.This command has several command-line options, but is easyto run and understand, for example:# freetotal used free shared buffers cachedMem: 30892 28004 2888 14132 3104 10444-/+ buffers: 14456 16436Swap: 34268 7964 26304302 Hour 20This shows a 32MB system with 34MB swap space.Notice that nearly all the system memoryis being used, and nearly 8MB of swap space has been used.By default, the free command displays memory in kilobytes, or 1024-byte notation.You canuse the -b option to display your memory in bytes, or the -m option to display memory inmegabytes.You can also use the free command to constantly monitor how much memoryis being used through the -s command.This is handy as a real-time monitor if you specifya.01-second update and run the free command in a terminal window under X11.Virtual Memory Reporting with the vmstatCommandThe vmstat is a general-purpose monitoring program, which offers real-time display of notonly memory usage, virtual memory statistics, but disk activity, system usage, and centralprocessing unit (CPU) activity.If you call vmstat without any command-line options, you llget a one-time snapshot, for example:# vmstatprocs memory swap io system cpur b w swpd free buff cache si so bi bo in cs us sy id0 0 0 7468 1060 4288 10552 1 1 10 1 134 68 3 2 96If you specify a time interval in seconds on the vmstat command line, you ll get acontinuously scrolling report.Having a constant display of what is going on with yourcomputer can help you if you re trying to find out why your computer suddenly slows down,or why there s a lot of disk activity.Viewing Your Shell s Ulimit ationsYou ve already seen how you can limit the size of core dump files previously in this hour.There are other settings you can set in your shell.If you re using the bash or pdksh (ksh) shell,you can use the ulimit command s -a option to print your current settings, for example:# ulimit -acore file size (blocks) 1000000data seg size (kbytes) unlimitedfile size (blocks) unlimitedmax memory size (kbytes) unlimitedstack size (kbytes) 8192cpu time (seconds) unlimitedmax user processes 256pipe size (512 bytes) 8open files 256virtual memory (kbytes) 2105343If you re using the tcsh or csh shell, you can use the limit command to list the current settings:$ limitcputime unlimitedfilesize unlimited2 0Basic System Administration 303datasize unlimitedstacksize 8192 kbytescoredumpsize 1000000 kbytesmemoryuse unlimiteddescriptors 256memorylocked unlimitedmaxproc 256These limits are different from limits for the root operator.The limits shown in this exampleare known as soft limits.To view the shell s hard limits, log in as the root operator, and usethe -a limit option (use -Ha for bash or ksh s ulimit command), for example:$ suPassword:# limit -hcputime unlimitedfilesize unlimiteddatasize unlimitedstacksize 8192 kbytescoredumpsize unlimitedmemoryuse unlimiteddescriptors 256memorylocked unlimitedmaxproc 256As you can see, viewing the limits as the root operator in the tcsh shell shows a much differentsituation.This is another good reason not to run as the root operator! As a sysadmin, you canuse these settings to limit the amount of memory or number of processes available to eachuser.This is extremely handy if you have a number of people working on your computer atthe same time, and you want to conserve system memory.For using Linux on a standalonecomputer under your normal login and working conditions, you ll find the default limitsquite reasonable.Reclaiming Memory with the kill CommandAs a desperate measure if you need to quickly reclaim memory, you can stop runningprograms by using the kill command.In order to kill a specific program, you should use theps command to list current running processes, and then stop any or all of them with the killcommand.By default, the ps command lists processes you own and which you can kill, for2 0example:# psPID TTY STAT TIME COMMAND367 p0 S 0:00 bash581 p0 S 0:01 rxvt582 p1 S 0:00 (bash)747 p0 S 0:00 (applix)809 p0 S 0:18 netscape index.html810 p0 S 0:00 (dns helper)945 p0 R 0:00 ps304 Hour 20The ps command will list the currently running programs and the program s process number,or PID.You can use this information to kill a process with# kill -9 809However, if you need to reclaim memory efficiently, you should use the ps command s -moption, which also lists the memory usage of each process, for example:# ps -mPID TTY MAJFLT MINFLT TRS DRS SIZE SWAP RSS SHRD LIB DT COMMAND747 p0 0 3 16 208 364 140 224 224 0 0 (applix)582 p1 151 274 124 184 436 128 308 268 0 10 (bash)959 p0 89 20 28 376 404 0 404 320 0 21 ps -m367 p0 305 826 220 316 600 64 536 428 0 27 bash810 p0 313 38 164 696 968 108 860 596 0 47 (dns helpe581 p0 212 508 28 960 1280 292 988 304 0 171 rxvt809 p0 2615 1205 3900 3692 8684 1092 7592 4644 0 699 netscapeBy using this information, you can see that if you want to reclaim the most memory, youshould stop the Netscape Web browser, as it is using nearly 9MB of system memory.Although you wouldn t normally use the kill command to stop programs, the killcommand can be helpful to stop runaway, or nonresponsive, programs.The kill commandworks by sending a signal to the Linux kernel, along with the PID, so the kernel can act onthe process.There are various signals you can use, although, as I ve pointed out, the -9, orSIGKILL option is the most abrupt and drastic
[ Pobierz całość w formacie PDF ]