Linux common system administration commands (top, free, kill, DF)

Source: Internet
Author: User
Tags cpu usage

top-c #任务管理器
free-m #查看内存使用情况
kill-9 2312 (description: Forced kill process kill-9 PID)
df-h #查看磁盘使用情况

First, top

1. Role

The top command is used to display the program process in progress, and the permissions are all users.

2. Format

top [-] [D delay] [Q] [C] [s] [s] [i] [n]

3. Main parameters

    • D: Specifies the interval of the update, in seconds.
    • Q: There are no delayed updates. If the user has a superuser, the top command will be executed with the highest precedence.
    • C: Displays the full path and name of the process.
    • S: Cumulative mode, which accumulates the CPU time of a child stroke that has completed or disappeared.
    • S: Safe mode.
    • I: Do not display any idle (idle) or useless (Zombie) travel.
    • N: Displays the number of updates and exits top when finished.

4. Description

The top command is a major command of Linux system Management, which gives you a lot of information. Here we illustrate the information it gives in the context of the diagram.

Figure 1 Display of the top command

In Figure 1, the first line represents the current time, the system startup time, the current number of system logon users, and the average load. The second line shows all the processes that were started, the currently running, suspended (sleeping), and the useless (Zombie) process. The third line shows the current usage of the CPU, including the proportion of the system occupied, the user usage ratio, idle (idle) ratio. Row four shows the use of physical memory, including total available memory, used memory, free memory, and memory consumed by the buffer. The five rows show the swap partition usage, including the total swap partition, used, idle, and the size used for the cache. Line six shows the most items, and the detailed explanations are listed below.

    • PID (Process ID): progress indicator number.
    • User: The username of the process owner.
    • PR: The priority level of the process.
    • NI: The value of the priority level of the process.
    • VIRT: The virtual memory value that the process occupies.
    • RES: The physical memory value that the process occupies.
    • SHR: Shared memory value used by the process.
    • S: The state of the process, where s indicates hibernation, R is running, Z represents a zombie state, and N indicates that the process precedence value is negative.
    • %CPU: The CPU usage that the process consumes.
    • %MEM: The percentage of physical memory and total memory that the process occupies.
    • Time+: The total CPU time that is consumed after the process is started.
    • Command: The start command name of the process startup, and if this line does not appear, the process will have a full command line.

While the top command is in use, you can also use some interactive commands to complete the functionality of other parameters. These commands are started by using shortcut keys.

  • < space;: Refresh now.
  • P: Sort According to CPU usage size.
  • M: Sorts according to the size of the memory used.
  • T: Sort by time, cumulative time.
  • Q: Exit the top command.
  • M: Toggles display memory information.
  • T: Toggles display of process and CPU status information.
  • C: Toggle display command name and full command line.
  • W: Writes the current settings to the ~/.TOPRC file. This is the recommended way to write top configuration files.

As you can see, the top command is a very powerful tool for monitoring systems and is especially important for system administrators. However, its disadvantage is that it consumes a lot of system resources.

5. Application examples

You can use the top command to monitor a specified user, and the default is to monitor processes for all users. If you want to view the situation of the specified user, press the "U" key in the terminal and enter the user name , the system will switch to the user's process run interface.

Second, free

2. Use

The free command is used to display memory usage, and the use of permissions is for all users.

2. Format

Free
[-b|-k|-m] [-O] [-s delay] [-t] [-v]

3. Main parameters

    • -b-k-M: Displays memory usage in bytes (KB, MB), respectively.
    • -S delay: Displays the number of seconds per second to show memory usage.
    • L-T: Displays the sum of the memory columns.
    • -O: Do not display buffer throttling columns.

4. Application examples

The free command is the primary command used to view memory usage. Compared to the top command, it has the advantage of being simple to use and consuming very little system resources. With the-s parameter, you can use the free command to continuously monitor how much memory is in use, which can be used as a handy real-time monitor.

#free-m-S 3

With this command, the terminal continuously reports memory usage (in megabytes ), updated every 3 seconds.

Third, kill

2. Use

The KILL command is used to abort a process.

2. Format

kill [-S signal |-P] [-a] pid ...
kill-l [Signal]

3. Parameters

    • -S: Specifies the signal to send.
    • -P: Analog send signal.
    • -L: Specifies a list of names for the signal.
    • PID: The ID number of the process to abort.
    • Signal: Indicates a signal.

4. Description

Processes are a very important concept in a Linux system. Linux is a multitasking operating system that often runs multiple processes at the same time. We don't care how these processes are distributed or how the kernel manages the allocation of time slices, and the concern is how to control these processes so that they can serve the user well.

The Linux operating system consists of three different types of processes, each of which has its own characteristics and attributes. An interactive process is a process that is initiated by a shell. The interactive process can be run either in the foreground or in the background. The batch process and terminal are not linked, and are a sequence of processes. A process that is started when the Linux system starts and runs in the background when the process is monitored (also called the System daemon). For example, HTTPD is the well-known Apache server monitoring process.

The KILL command works by sending a system operation signal to the kernel of the Linux system and the process identification number of a program, and then the system kernel can operate on the processes specified by the process identification number. For example, in the top command, we see that the system runs many processes, and sometimes it needs to use kill to abort some processes to improve system resources. When explaining the installation and landing commands, it was mentioned that the function of multiple virtual consoles is to switch to another virtual Console to shut down the program when a program error causes the system to deadlock. The command that is used at this point is kill, because Kill is a direct call to most shell internal commands.

5. Application examples

(1) forcibly abort (often used to kill) a process with an identification number of 324:

#kill-9 324

(2) Unlocking the Linux system deadlock

In Linux, there are times when a program crashes and is in a deadlock state. You do not have to restart your computer at this time, just abort (or shut down) the problematic program. When Kill is in the X-window interface, the main program (except for the crashing program) normally starts. At this point, open a terminal, where the problematic program is aborted. For example, if the Mozilla browser program has a deadlock situation, you can use the KILL command to abort all programs that contain the Mozolla browser. First use the top command to investigate the PID of the program, and then use the KILL command to stop the program:

#kill-sigkill XXX

where xxx is the process identification number of the program that contains the Mozolla browser.

(3) Use the command to reclaim memory

We know that memory is very important to the system, and reclaiming memory can improve system resources. The KILL command can be used in a timely manner to abort some "deviant" programs or for a long time without corresponding programs. For example, using the top command to discover a useless (Zombie) process, you can use the following command:

#kill-9 XXX

where xxx is a useless process identification number.

Then use the following command:

#free

You will see an increase in available memory capacity.

(4)killall command

Linux also provides a killall command that can directly use the name of the process rather than the process identification number, for example:

# killall-hup inetd
Iv. Viewing disk space remaining df (DF-H)

Usage:df [Options] ... [File] ...

Displays the information for each < file > file system that is located, by default showing all file systems.

The parameters that must be used for the long option are also required when using the short option.

  • -A,--all includes a file system of size 0 blocks
  • -B,--block-size= size block with specified < size > bytes
  • -H,--human-readable file system size in an easy-to-understand format (e.g. 1K 234M 2G)
  • -H,--si similar to-H, but takes 1000 of the time instead of 1024
  • -I,--inodes displays inode information instead of block usage
  • -K is--block-size=1k
  • -L,--local only displays the native file system
  • --no-sync No sync action (default) before getting usage data
  • -P,--portability using POSIX output format
  • --sync sync action before getting usage data
  • -T, the--type= type only prints the file system information for the specified < type >
  • -T,--print-type print file system type
  • -X, the--exclude-type= type only prints file system information that is not a specified < type >
  • -V (this option is not processed)

Linux common system administration commands (top, free, kill, DF)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.