Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to view the status information of Linux system

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how to view the status information of the Linux system, the content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

Preface

Among the common commands in Linux, some commands can be used to view the status of the system. By understanding the current state of the system, it can help us to better maintain the system or locate the problem. Here is a brief introduction to these commands.

View system uptime, load-uptime

Sometimes we want to know when the system was last reset or how long the system has been running, we can get this information through the uptime command:

Uptime20:47:06 up 50 min, 1 user, load average: 0.75, 0.84, 0.93

The information displayed from left to right is the current time, the running time, the number of user logins, and the average load of the system in 1 minute, 5 minutes, and 15 minutes.

Check that the system is logged in user-whowho-ahyb tty7 2018-09-30 19:57 (: 0)

The who command allows you to see which users have logged in to the host through which ip.

View system version related information-uname

For example:

Uname-aLinux ubuntu16.04 4.15.0-34-generic # 37~16.04.1-Ubuntu SMP Tue Aug 28 10:44:06 UTC 2018 x86 "64 GNU/Linux

From the results, you can see the operating system version (ubuntu16.04), CPU type (x86 / 64) and other information.

View the current environment variable-export

Environment variables affect the operation of the program, so sometimes you need to look at the environment variables of the current environment:

Export

View directory and file footprint-du

The du command directly displays the space occupied by each directory and its files under the current directory. The-max-depth parameter allows you to specify the directory level that is displayed.

For example, if you only want to display the total space occupied by each directory under the current directory, you can use:

Du-h-- max-depth=1 19m. / python9.0M. / git321M. / hexo17M. / vim1.4M. / shell81M. / redis316M. / books48M. / c810M.du-sh # only counts the total size of the current directory 810m

Where-h indicates that the size is displayed in easy-to-read units, that is, MMagazi Maxwell depthods 1 indicates the directory hierarchy. From the command results, we can see the amount of space occupied by each subdirectory under the current directory, as well as the total space size.

View the mount point space-df

For example:

Df-h file system capacity used available mount point udev 3.9G 0 3.9G 0 / devtmpfs 786M 9.5M 776m 2% / run/dev/sda10 24G 9.8G 13G 45% / tmpfs 3.9G 43m 3.8G 2% / dev/shmtmpfs 5.0M 4.0K 5.0M 1 % / run/locktmpfs 3.9G 0 3.9G 0% / sys/fs/cgroup/dev/sda11 454M 274M 153M 65% / boot/dev/sda15 55G 5.2G 47G 10% / home/dev/sda1 256M 31M 226M 12% / boot/efi/dev/sda14 4.6G 9.9M 4.4G 1% / tmptmpfs 786M 60K 786m 1% / run/user/1000

From the results, we can see the total space and available space for each mount point. When the disk file takes up a large amount of space, it may cause the system to run slowly, so you can clean up the disk accordingly according to the result.

Check memory availability-free

The free command can be used to display the physical memory available on the system, swap memory, and the buffer used by the kernel:

Free-h total used free shared buff/cache availableMem: 7.7G 2.3G 2.6G 268m 2.8G 4.7GSwap: 7.6G 0B 7.6G

From the execution results, you can see the situation of used memory and free memory. Similarly, when there is insufficient memory, it may cause the program to run abnormally or the system to stutter.

View the memory usage of the process-pmap

The pmap command is used to view information about process memory:

Pmap pid # pid is the process id You can obtain 6030:. / main0000000000400000 4K libc-2.23.so00007fc3847ac000 libc-2.23.so00007fc3847ac000 4K libc-2.23.so00007fc3847ac000 rw--- libc-2.23.so00007fc3847ae000 16K rw--- through the ps command-main0000000000601000 4K rw--- main00000000017d2000 132K rw--- [anon] 00007fc3843e8000 1792K Rafael-libc-2.23.so00007fc3845a8000 2048K-libc-2.23.so00007fc3847a8000 16K Rafael [ Anon] 00007fc3847b2000 152K rlichashi-ld-2.23.so00007fc3849b9000 12K rw--- [anon] 00007fc3849d7000 4K rMurashi-ld-2.23.so00007fc3849d8000 4K rw--- ld-2.23.so00007fc3849d9000 4K rw--- [anon] 00007ffcf2018000 132K rw--- [stack] 00007ffcf2175000 12K Rakashi-[anon] 00007ffcf2178000 8K Rafael-[anon] ffffffffff600000 4K Rafael XLV- [anon] total 4356K

We can constantly optimize our program according to the space occupied by each part of the process.

View virtual memory statistics-vmstatvmstatprocs-memory- swap---io-----system---cpu- r b swpd free buff cache si so bi bo in cs us sy id wa st 2214960 407828 2572148 00 126 57 377 1006 82 88 2 0

The output value of vmstat can help us understand the performance of the current system. For example, if the values of si (the amount of memory written from the swap area to memory per second) and so (the amount of memory written to the swap area per second) are often greater than 0, there may not be enough memory, so swap space is needed. For example, when the value of us (percentage of user process execution time) is high, it means that the user process consumes more CPU resources. When the value of wa (percentage of IO wait time) is high, it indicates that the IO wait situation is serious.

View the external IPcurl ifconfig.me of the current host

View network port information-ifconfig

Ifconfig can be used to view ip address, network port and other information:

Ifconfig-a

View ip address-ip

Sometimes you may not be able to see all the ip addresses using the ifconfig command, so you can use:

Ip addr

View network connection status-netstat

The netstat command can view the network connection status and is usually used to diagnose network-related problems. For example, check whether the port is occupied, whether the connection has been released, whether the service is listening, and so on.

View CPU utilization, etc.-top

The top command can be used to view the system's CPU utilization, memory footprint, and so on:

Toptop-22:06:11 up 12 min, 1 user, load average: 0.87,1.12, 1.02Tasks: 235 total, 1 running, 180 sleeping, 0 stopped, 0 zombie%Cpu (s): 6.9 us, 2.1 sy, 0.0 ni, 90.8 id, 0.1 wa, 0.0 hi, 0.1 si, 0.0 stKiB Mem: 8039576 total, 3106072 free, 2486744 used, 2446760 buff/cacheKiB Swap: 8002556 total, 8002556 free 0 used. 4804820 avail Mem PID USER PR NI VIRT RES SHR S% CPU% MEM TIME+ COMMAND 3389 hyb 20 0 1243184 108880 68152 S 6.0 1.4 0 compiz 6414 hyb 20 0 1299428 209808 84204 S 6.0 2.6 0 avail Mem PID USER PR NI VIRT RES SHR S 07.48 chrome 4879 hyb 20 0 1670760 270444 127124 S 5.3.4 32.89 chrome

View interprocess relationships-pstree

The parent-child relationship between processes can be seen through the pstree command, which displays this information in a tree structure:

Pstreesystemd ─┬─ ModemManager ─┬─ {gdbus} │ └─ {gmain} ├─ NetworkManager ─┬─ dhclient │ ├─ dnsmasq │ ├─ {gdbus} │ └─ {gmain} ├─ accounts-daemon ─┬─ {gdbus} │ └─ {gmain} ├─ acpid ├─ atd ├─ avahi-daemon ─── avahi-daemon ├─ bluetoothd ├─ colord ─┬─ {gdbus} │ └─ {gmain} ├─ cron ├─ cups-browsed ─┬─ {gdbus} │ └─ {gmain} ├─ cupsd ─── 3 * [ Dbus] ├─ dbus-daemon ├─ gnome-keyring-d ─┬─ {gdbus} │ ├─ {gmain} │ └─ {timer} (only part of the content is displayed)

Summary

In fact, many of the relevant command information mentioned earlier are obtained from system files, for example, / proc/meminfo saves memory-related information and / proc/net/dev saves network traffic-related information. However, they are all static values, but we can observe this information dynamically in combination with the watch command, such as:

Watch-n 1 cat / proc/meminfo watch-n 1 cat / proc/net/dev

The above command indicates that cat / proc/meminfo or cat / proc/net/dev is executed every second, so we can see the memory information or Nic traffic information refreshing in real time.

What is Linux system Linux is a free-to-use and free-spread UNIX-like operating system, is a POSIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.

On how to view the status of the Linux system information is shared here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report