[Comprehensive explanation of Linux commands] 190. Detailed explanation of Linux commands: groupadd and free

groupadd

Used to create a new workgroup

Additional information

groupaddThe command is used to create a new workgroup, and the new workgroup information will be added to the system file.

grammar

groupadd [选项] [参数]

Options

  • -g: Specify the id of the new workgroup;
  • -r:Create a system workgroup, the group ID of the system workgroup is less than 500;
  • -K: Overwrite configuration file /ect/login.defs;
  • -o: Allows adding workgroups with non-unique group IDs.

parameter

  • Group name: Specify the group name of the new workgroup.

Example

Create a new group and set the group ID to join the system:

groupadd -g 344 jsdigname

At this time, /etc/passwdan item with a group ID (GID) of 344 is generated in the file.

free

Show memory usage

Additional information

freeThe command can display the amount of unused and used memory in the current system, and can also display the memory buffer used by the kernel.

grammar

free [选项]

Options

  • -b: Display memory usage in Byte;
  • -k: Display memory usage in KB;
  • -m: Display memory usage in MB;
  • -g: Display memory usage in GB;
  • -o: Do not display the buffer adjustment column;
  • -s<间隔秒数>: Continuously observe memory usage;
  • -t: Display the memory sum column;
  • -V: Display version information.

Example

Display memory usage information as a sum:

free -t

Periodically query memory usage information and execute the command every 10 seconds:

free -s 10

Show memory usage:

free -m
total used free shared buffers cached
2016 1973 42 0 163 1497
-/+ buffers/cache 312 1703
Swap 4094 0 4094

Explanation of the first part of Memthe line:

  • total: Total memory;
  • used: The amount of memory that has been used;
  • free: The number of free memory;
  • shared: Currently deprecated;
  • buffers:Number of cache memory;
  • cached: Number of cache memory.

relation:total = used + free

The second part (-/+ buffers/cache) explanation:

  • (-buffers/cache)Number of used memory: Memin the first part of the lineused – buffers – cached
  • (+buffers/cache)Number of free memory: Memin the first part of the linefree + buffers + cached

It can be seen -buffers/cachethat what is reflected is the memory actually eaten by the program, and +buffers/cachewhat is reflected is the total amount of memory that can be appropriated.

The third part refers to the swap partition.

The fourth line of the output is for the swap partition SWAP, which is what we usually call virtual memory.

memDifference: The difference between used/free in the second line ( ) and used/free in the third line (-/+ buffers/cache). The difference between the two lies in the perspective of use. The first line is from the perspective of the OS. Because for the OS, it is buffers/cachedused, so its available memory is 2098428KB and the used memory is 30841684KB, including, The kernel (OS) uses +buffers+cached used by +Application (X, oracle, etc).

buffers/cachedThe third line refers to the fact that from the application point of view, it is available to the application , because buffer/cached is to improve the performance of file reading. When the application needs to use memory, buffer /cached will be recycled quickly.

So from the perspective of the application, available memory = system free memory + buffers + cached. For example, the available memory of this machine is:

18007156 = 2098428KB + 4545340KB + 11363424KB

Next, we explain when memory will be swapped, and in what way.

When the available memory is less than the rated value, a swap will occur. How to see the rating:

cat /proc/meminfo

Swapping will reduce the number of physical pages used in the system in three ways:

  • Reduce buffer and page cache sizes,
  • Swap out system V type memory pages,
  • Swap out or discard pages (memory pages occupied by Application, that is, insufficient physical memory).

In fact, using swap sparingly does not affect system performance.

So buffersand cachedare both caches, what is the difference between the two?

In order to improve disk access efficiency, Linux has made some elaborate designs. In addition to dentrycaching (used in VFS to accelerate the conversion of file path names to inodes), Linux also adopts two main Cache methods:

  • Buffer Cache: for reading and writing disk blocks;
  • Page Cache: for reading and writing file inodes.

These Cache effectively shorten the time of I/O system calls (such as read, write, getdents). Disk operations are divided into logical level (file system) and physical level (disk block). These two caches cache logical and physical level data respectively.

Page cache is actually for the file system and is a cache of files. Data at the file level will be cached in the page cache. The logical layer of the file needs to be mapped to the actual physical disk, and this mapping relationship is completed by the file system. When the data in the page cache needs to be refreshed, the data in the page cache is handed over to the buffer cache, because the buffer cache caches disk blocks. However, this processing has become very simple after the 2.6 version of the kernel, and there is no real cache operation.

Buffer cache is a cache for disk blocks. That is, in the absence of a file system, data that directly operates on the disk will be cached in the buffer cache. For example, the metadata of the file system will be cached in the buffer cache.

Simply put, the page cache is used to cache file data, and the buffer cache is used to cache disk data. When there is a file system, when operating on a file, the data will be cached in the page cache; if you directly use ddother tools to read and write to the disk, the data will be cached in the buffer cache.

So when we look at Linux, as long as you don't use swap's swap space, you don't have to worry about having too little memory. If you often use a lot of swap, you may need to consider adding physical memory. This is also the standard used by Linux to determine whether the memory is sufficient.

If it is an application server, you generally only look at the second line, +buffers/cache, which means that the free memory is too little for the application, and it is time to consider optimizing the program or adding memory.

Learn from scratchpython

[Learn python from scratch] 92. Use Python’s requests library to send HTTP requests and process responses
[Learn python from scratch] 91. Use decorators and dictionaries to manage request paths in a simple web application
[Learn python from scratch] 93. Use dictionary management Request path
[Learn python from scratch] 89. Use WSGI to build a simple and efficient Web server
[Learn python from scratch] 88. Detailed explanation of WSGI interface: realize simple and efficient web development
[Learn python from scratch] 87. Manually build an HTTP server in Python Implementation and multi-threaded concurrent processing
[Learn python from scratch] 86. In-depth understanding of the HTTP protocol and its role in browser and server communication
[Learn python from scratch] 85. Application of parallel computing technology in Python process pool
[Learn python from scratch] ] 84. In-depth understanding of threads and processes
[Learn python from scratch] 83. Python multi-process programming and the use of process pools
[Learn python from scratch] 82. Chat program implementation based on multi-threading
[Learn python from scratch] 81. Python more Application of thread communication and queue
[Learn python from scratch] 80. Thread access to global variables and thread safety issues
[Learn python from scratch] 79. Thread access to global variables and thread safety issues
[Learn python from scratch] 78. File download case
[ Learn python from scratch] 77. TCP server programming and precautions
[learn python from scratch] 76. Server and client: key components of network communication
[learn python from scratch] 75. TCP protocol: reliable connection-oriented transmission layer communication protocol
[Learn python from scratch] 74. UDP network program: Detailed explanation of port issues and binding information
[Learn python from scratch] 73. UDP network program - sending data
[Learn python from scratch] 72. In-depth understanding of Socket communication and creation of sockets Method
[Learn python from scratch] 71. Network ports and their functions
[Learn python from scratch] 70. Network communication methods and their applications: from direct communication to routers to connect multiple networks
[Learn python from scratch] 69. Network communication and IP address classification analysis
[Learn python from scratch] 68. Greedy and non-greedy modes in Python regular expressions
[Learn python from scratch] 67. The re module in Python: regular replacement and advanced matching technology
[Learn python from scratch] 66 .In-depth understanding of regular expressions: a powerful tool for pattern matching and text processing
[Learn python from scratch] 65. Detailed explanation of Python regular expression modifiers and their applications
[Learn python from scratch] 64. The re.compile method in Python regular expressions Detailed explanation of usage
[Learn python from scratch] 63. Introduction to the re.Match class and its attributes and methods in regular expressions
[Learn python from scratch] 62. Python regular expressions: a powerful string matching tool
[Learn python from scratch] 61. Detailed explanation and application examples of property attributes in Python
[Learn python from scratch] 60. Exploration generator: a flexible tool for iteration
[Learn python from scratch] 59. Iterator: An efficient tool for optimizing data traversal
[Learn python from scratch] 58. Custom exceptions in Python and methods of raising exceptions
[Learn python from scratch] 57. Use the with keyword in Python to correctly close resources
[Learn python from scratch] 56. The importance and application of exception handling in programming
[Learn python from scratch] 55. Serialization and sum in Python Deserialization, application of JSON and pickle modules
[Learn python from scratch] 54. Writing data in memory
[Learn python from scratch] 53. CSV files and Python’s CSV module
[Learn python from scratch] 52. Reading and writing files - Python file operation guide
[Learn python from scratch] 51. Opening and closing files and their applications in Python
[Learn python from scratch] 49. Object-related built-in functions in Python and their usage
[Learn python from scratch] 48 .Detailed explanation of inheritance and multiple inheritance in Python
[Learn python from scratch] 47. The concept and basic use of inheritance in object-oriented programming
[Learn python from scratch] 46. Analysis of __new__ and __init__ methods and singletons in Python Design Patterns
[Learn python from scratch] 45. Class methods and static methods in Python
[Learn python from scratch] 44. Private properties and methods in object-oriented programming
[Learn python from scratch] 43. Examples in Python object-oriented programming Properties and class attributes
[Learn python from scratch] 42. Built-in properties and methods in Python
[Learn python from scratch] 41. python magic method (2)
[Learn python from scratch] 40. python magic method (1)
[Learn python from scratch] 39. Basic object-oriented syntax and application examples
[Learn python from scratch] 38. How to use and import Python packages
[Learn python from scratch] 37. The use and precautions of Python custom modules
[Learn python from scratch] Learn python] 36. Methods and techniques of using pip for third-party package management in Python
[Learn python from scratch] 35. Python common system modules and their usage
[Learn python from scratch] 34. Detailed explanation of the import and use of Python modules
[ Learn python from scratch] 33. The role of decorators (2)
[Learn python from scratch] 32. The role of decorators (1)
[Learn python from scratch] 31. In-depth understanding of higher-order functions and closures in Python
[From Learn python from scratch】30. In-depth understanding of recursive functions and anonymous functions
【learn python from scratch】29. "Detailed explanation of function parameters" - understand the different uses of Python function parameters
【learn python from scratch】28. Local variables and global variables in Python Variables
[Learn python from scratch] 27. The use of Python functions and nested calls
[Learn python from scratch] 25. Functions: a tool to improve the efficiency of code writing
[Learn python from scratch] 24. String operations and traversal methods in Python
[Learn python from scratch] 23. How to use sets (set) and common operations in Python
[Learn python from scratch] 22. Add, delete, modify, and query dictionary variables in Python
[Learn python from scratch] 21. Python tuples and dictionaries
[Learn python from scratch] 20. Python list operation skills and examples
[Learn python from scratch] 19. Applications of looping through lists and list nesting
[Learn python from scratch] 18. Detailed explanation of the basic operations of Python lists (1)
[From Learning python from scratch】 17. The format method of Python strings (2)
【Learning python from scratch】 16. The format method of Python strings (1)
【Learning python from scratch】 15. In-depth understanding of strings and character set encoding
【From Learning python from scratch】14. Common operations on Python strings (2)
【Learning python from scratch】13. Common operations on Python strings (1)
【Learning python from scratch】12. Python string operations and applications
【Learning python from scratch】 11. Python loop statements and control flow
[Learn python from scratch] 10. Detailed explanation of Python conditional statements and if nesting
[Learn python from scratch] 09. Conditional judgment statements in Python
[Learn python from scratch] 08. Python understands bit operations operator, operator priority
[Learn python from scratch] 07. Detailed explanation of Python operators: assignment, comparison and logical operators
[Learn python from scratch] 06. Use arithmetic operators in Python for calculations and string concatenation
[Learn from scratch] python ] 05. Output and input in Python
[Learn python from scratch] 04. Basics of Python programming: variables, data types and identifiers
[Learn python from scratch] 03. Python interactive programming and detailed explanation of comments
[Learn python from scratch] 02. Introduction to development tools
[Learn python from scratch] 01. Install and configure python

Guess you like

Origin blog.csdn.net/qq_33681891/article/details/133125935
Recommended