Linux core built-in management commands

Posted by robindean on Sat, 15 Feb 2020 20:16:56 +0100

4.1 placeholder ":

(1) An example of using placeholders in Shell scripts

if [ $i -eq 1 ] #Conditional expression
    then
        :   #If the if judgment statement is used in the Shell script, some operations are usually performed after the judgment is successful, but sometimes it is not known what operations are performed or it is not necessary to perform some operations. However, due to the fixed syntax format of if statement, it is necessary to write a command to occupy the position, because if there is no content in this line, the syntax error will be reported, and the placeholder of ":" will be used at this time. However, please be assured that this command will not have any impact on your Shell script, which is a bit like the pass of other programming languages Same field
else
    echo "hello world"
fi

4.2 ulimit modifies system resource usage restrictions

4.2.1 order details

Function Description:

The ulimit command is used to view the usage of system resources. At the same time, it can also modify the quota allocated to system resources by processes or users

Option Description:

Parameter options interpretative statement
-a Display all current system resource usage restrictions
-n Display or set the maximum number of open files

4.2.2 use examples

(1) Display all current system resource usage restrictions

[root@Mr_chen ~]# ulimit -a 
core file size          (blocks, -c) 0  #The maximum value of core file is 100blocks
data seg size           (kbytes, -d) unlimited  #The data segment of the process can be any size
scheduling priority             (-e) 0          #Scheduling priority
file size               (blocks, -f) unlimited  #File can be any size
pending signals                 (-i) 7696       #Up to 7696 pending signals
max locked memory       (kbytes, -l) 64         #The maximum physical memory locked by a task is 64KB
max memory size         (kbytes, -m) unlimited  #Maximum amount of physical memory resident of a task
open files                      (-n) 1024       #A task can open up to 1024 files at the same time
pipe size            (512 bytes, -p) 8          #The maximum space of the pipeline is 4096 (512 * 8) bytes
POSIX message queues     (bytes, -q) 819200     #The maximum message queue size for POSIX is 819200 bytes
real-time priority              (-r) 0          #Real time scheduling priority
stack size              (kbytes, -s) 10240      #The maximum stack size for a process is 10240 bytes
cpu time               (seconds, -t) unlimited  #CPU time used by the process
max user processes              (-u) 7696       #The maximum number of processes (including threads) opened by the current user at the same time is 7696
virtual memory          (kbytes, -v) unlimited  #There is no limit to the maximum address space of the process
file locks                      (-x) unlimited  #There is no limit to the maximum number of files that can be locked

(2) Increase the number of server open file descriptors

[root@Mr_chen ~]# ulimit -n
1024        #By default, the maximum number of file opens (also called file descriptor) of the new system is 1024. This value is too small for servers in the production environment, so it is usually increased in the server optimization phase
[root@Mr_chen ~]# ulimit -n 65535   #The number of adjustments is 65535, but those adjusted by the command only take effect for the current window, so the configuration file needs to be modified
[root@Mr_chen ~]# ulimit -n
65535
[root@Mr_chen ~]# echo "* - nofile 65535" >> /etc/security/limits.conf  #The modification profile is permanently effective, * means it is effective for any user
Source of this article: https://www.cnblogs.com/chensiqiqi/p/9163094.html

Topics: shell Programming