当前位置:网站首页>Embedded from entry to mastery (buried) - sharing of ultra detailed knowledge points 3
Embedded from entry to mastery (buried) - sharing of ultra detailed knowledge points 3
2022-07-23 12:34:00 【xiq1212】
Linux From entry to mastery ( The grave )
- Structure
a) Concept
A structure is a type of construction data , Used to describe a message , Or a new data type constructed by an object . The structure makes C Language has the idea of object-oriented .
b) Format 1
Struct Structure name
{
data type Member variables 1;
data type Member variables 2;
……
data type Member variables n;
}
Be careful : - Visiting members , use . Degraded access .
- Structural variables can be assigned to each other as a whole , The same members can assign values to each other .
- When the structure member is impossible, the function , It can be :
a) Basic data types .
b) Other structural variables .
c) The pointer : Class A 、 second level 、 A function pointer 、 Array pointer 、 Structure pointer .
d) Array : One dimensional array 、 Two dimensional array 、 Function pointer array .
Structure variable definition format :
Struct Structure name Variable name
Initialization of structure variables - First define the structure type , Redefining variables
a) The definition is not initialized , You need to assign initial values to members one by one .
b) Direct initialization during definition , The corresponding position sequence assignment .
c) Dot and wait initialization - Define variables as well as structure types ( The structure definition is under the header file ,main On )
- and typedef Use a combination of
a) First define the structure type and then name it .
b) Rename while defining the structure type , The structure name can be omitted .
c) Format 2:
struct
{
data type Member variables 1;
data type Member variables 2;
……
data type Member variables n;
};
Define variables while defining types , Generally, in nested structure types .
combination typedef Use .
d) Structure pointerDefine format :
Struct Structure name * Pointer variable name ;Access structure members :
a)(* Pointer to the variable ) Member variable name : Take the value of the whole structure variable first , And then use . Demote access members .
b) Pointer to the variable -> Member variable name : Direct pointer to the member to access the value of the member .
e) Array of structsDefine format :
Struct Structure name Array name [ Subscript ].
2. Space occupied by structure variables
The space occupied by a structure variable is the sum of the space opened up by the corresponding types of all members .
however , There is an alignment rule , Align with the largest space occupied by all member data types to open up memory space .32 The bit operating system is up to 4byte alignment ,64 Bit operating system , The maximum is 8byte alignment .Shared body ( Consortium )
a) Concept : All members share a memory space , Memory opened up by public .
The size of the space is based on the members that occupy the largest space .
b) Format
Union Community name
{
data type Member variable name 1;
data type Member variable name 2;
……
data type Member variable name n;
};
Be careful :When a community is used, the value of a member is used at the same time . That is, initialize the members you want to use
The definition format of the common body is similar to that of the structure , Accessing member content also uses . Degraded access .
Because the public body shares a memory space , Not very safe . That is, the use of common objects is relatively less . Mainly use the common body to test pc Large and small end .
enumeration
Enum ( Basic variable type )
Stm32 linux drive QT in
#define MON 1
#define TUES 2
……
#define SUN 7
Use enumeration types to represent constants
a) Format
Enum Enumeration name
{
Members of the enumeration 1,
Members of the enumeration 2,
……
Members of the enumeration n,
};// Semicolons cannot be omitted
Generally, enumeration is used to represent some fixed values , such as , It takes only seven days to fix a week .
Be careful :Once the enumeration type is defined , The member value in the enumeration determines , Members in an enumeration can only represent an integer , By default, the first member represents an integer 0, The members behind accumulate in turn 1.
The members in the enumeration are separated by commas .
You can specify an initial value for a member in the enumeration , The member behind a member , Add... To the initial value 1.
When the enumeration type is successfully defined , The value of the enumeration member has been determined , You can't change it when you use it next .
Generally used in and switch The combination makes the code more intuitive and clear .
Linux and unix The difference between
a) Two big differencesLinux It is free software for developing source code , and unix It is a traditional commercial software that protects the intellectual property rights of source code .
Unix Most of the systems are matched with hardware , and Linux It can run on a variety of hardware platforms .
b) redhat and ubuntu The difference betweenredhat More for servers , Less frequent updates , Stable .
ubuntu humanitarianism , Interface optimization is better , Follow xinkuai , Good experience .
Linux Architecture
a) application layer :app shell
b) Kernel layer : Five functionsfile management
Equipment management
Network management
memory management
Process management
c) Hardware layer : mouse 、 Keyboard, etc .
C library : It provides a set of standard function interfaces for input and output , It can be used on different operating systems . Indirect system call
system call : The kernel provides input and output function interfaces up , Based on the kernel , Function interfaces can only be used on this operating system . Different operating systems provide different system call interfaces .Check the operating system version and kernel version
see linux Kernel version :unname -r/-a
see ubunt Version of :lsb_release -a
Shut down or restart :shutdown
To turn it off
a) Shutdown immediately :sudo shutdown -h now
b) Timed shutdown :sudo shutdown -h + Timerestart
a) Restart immediately 1:sudo shutdown -r now
b) Restart immediately 2:reboot now
c) Restart regularly :sudo shutdown -r + Timeenvironment variable
Commands for viewing environment variables :printenv or env
PATH: The default search path of the command is saved , The path uses : separate .
If you use your executable program as a command :
a) Move the executable program to PATH The variable is saved in the path .
b) Save the path where the executable exists to PATH In the environment variables .Linux Software installation
Understand the types of software packages installed on different systems :
System Installation package type
Windows .exe
Android .apk
Ubunt .deb
Redhead .rpmlinux Popular software package management mechanism
a) debian Linux Put forward :deb software package
b) redhead Linux Put forward :rpm software packagedeb Classification of software packages
a) Binary packages :.deb
b) Source package :.dscPackage management tools :dpkg apt
Dpkgcharacteristic : Installing the software requires that the installation package of the installed software exists , Cannot detect dependencies between software , You cannot get packages from the mirror site , Network is not required for installation .
Software
Warehouse 1( Address ) Warehouse 2( network ) Warehouse 3 Warehouse 4
Baidu ( Source ) Mirror site firefox Googlecommand :
a) sudo dpkg -i Complete software name : Install the software
b) sudo dpkg -r The software name : Uninstall software
c) sudo dpkg -s The software name : Check the installation status of the software
d) sudo dpkg -p The software name : Uninstall completely
e) sudo dpkg -l The software name : List the documents of the softwarePackage management tools apt
Format :apt- A set of commands :apt-get、apt-cache
characteristic : Installing the software does not require the existence of the software installation package , Can detect dependencies between software , The software package can be obtained from the mirror site , Installation requires network .apt-get command : install 、 uninstall
a) sudo apt-get install The software name : Download the installation software
b) sudo apt-get remove The software name : Uninstall software
c) sudo apt-get download The software name : Download the package
d) sudo apt-get source The software name : Download source package
e) sudo apt-get updata: Update software source
f) sudo apt-get upgrade: Update all software
g) sudo apt-get clean: Clearly download the software package
h) sudo apt-get check: Check the integrity of dependencies in the system .apt-cache command : Check the installation status 、 Dependency relationship
a) sudo apt-cache show The software name : Get the detailed description of the binary package
b) sudo apt-cache policy The software name : Check the installation status
c) sudo apt-cache depends The software name : The software I rely on
d) sudo apt-cache rdepends The software name : Which software depends on meIP The classification of
IPV4 32 position In dotted decimal
192.168.50.14 C class IPV4 The data before a point is a 8bit( We often use IPV4 C Class is enough )
IPV4 classification : Five category
a) A class : One byte network number , Three byte host number . The first place is fixed as 0.
Network segment value range :0000 0000——0111 1111
The number of hosts that can be connected to a network segment :2^24-2
b) B class :2 Byte network number ,2 Host number of bytes . First fixed position 10.
Network segment value range :1000 0000 0000 0000 -1011 1111 1111 1111
The number of hosts that can be connected to a network segment :2^16-2
c) C class :3 Byte network number ,1 Byte host number . First fixed position 110.
The number of hosts that can be connected to a network segment :2^8-1
d) Multicast address , First fixed position 1110
e) Reserved for use , The first place is fixed as 1111.know shell
Command line parser
Shell Parser version :sh、csh、ksh、bash
Shell、 kernel 、 Hardware 、 The relationship between users :
a) The user prompts the terminal to input commands or keys from the command line , Submit to shell
b) Shell Convert commands to instructions recognized by the bit kernel
c) The kernel drives the hardware device to realize the corresponding instruction function , Submit the execution results to shell.
d) Shell Submit the interpretation of the feedback results to the user for identification .shell Basic commands
a) History query :history
b) Command alias :aliasShell Special characters for
wildcard
a) a)*: Match any length character
b) b)?: Matches any character
c) c)[ - ]: Match any character in the range
d) d)[……]: Match any specified character
e) e)[^……]: Match any character except the specified character .The Conduit |
Take one command as input to another .wc command
a) wc-l file name : Look at the number of lines in the file
b) wc-w file name : Number of words in the file
c) wc-c file name : Number of file characters
d) wc-m file name : file sizegrep: Query the string in the file
grep “ character string ” file nameI / O redirection
a) a)>file: take file Redirect to output source , New mode
b) b)>>file: take file Redirect to output source , Append mode
c) c)<file: take file Redirect to input source .
d) d)2> or &>file: take file File redirection as error message output source .Command substitution character : stay Esc Under key
Take the output of one command as an argument to another .Shell Basic system commands
man:man man: see man Manual function
sudo passwd user name : Change user password
su: Switching users
a) su: Default switch to root
b) sudo su user name : Switch to the specified user
c) exit: The user who exited the switchdata Check the date of the system
a) sudo data -s year / month / Japan
b) sudo data -s when : branch : secondclear Clear the screen
df-Th Displays the usage of disk space
mount: mount
How to mount USB disk
a) Insert the USB drive into the computer and identify it in the virtual machine
b) adopt df-Th Check the device name and file type of the USB drive
c) perform sudo mount -t file type Equipment name Mount point
d) Uninstall method “sudo umount Mount pointTFTP、nfs、samba The server
install TFTP File transfer server :Check whether the computer is installed
Sudo dpkg -s tftpd -hpainstall
Sudo apt-get install tftp-hpaIt needs to be configured correctly TFTP To ensure normal use
Sudo vi/etc/default/tftp-hpaestablish tftpboot Catalog
Sudo mkdir /hmoe/tftp
Sudo chmod 777 /home/tftpstart-up tftp service
Sudo service tftpd-hpa restartTest client program
Tftp localhost or tftp127.0.0.1( Native ip Address )/ The other person's IP Address
Enter the command :
Put a.c// Upload files
Get a.c// Download the file
q// sign out
install nfs service :Check whether the computer is installed
Sudo dpkg -s nfs-kernel-serverinstall
Sudo apt-get install nfs-kernel-serverNeed modification nfs Configuration file for
Sudo vi/etc/exports file
Modified as :/home/hq/nfsRestart the service :sudo service nfs-kernel-server restart
take /home/hq/nfs The directory is attached to mnt Next (192.168.1.107 When the virtual machine ip)
Sudo mount-t nfs 192.168.1.107:/home/hq/nfs/mntuninstall :sudo umount/mnt
install samba The server :Check whether the computer is installed
Sudo dpkg -s sambainstall
Sudo apt-get install sambaNeed modification nfs Configuration file for
Sudo vi/etc/samba/smb.confUser management command
adduser Create user
sudo adduser user nameusermod Modify or add users
a) modify :sudo usermod -l A new user name user name
b) add to :sudo usermod -aG user GroupDelete user
Sudo deluser user nameDelete the group
Sudo delgroup Group nameProcess related commands
process : A process is an execution of a program .
Program : Executable binary files stored in disk space .File system commands
File system type
a) Disk file system : Hard disk 、U disc
b) Network file system :nfs service 、samba
c) Virtual file system :tmpfs
The format of the file system is :ext、ext2、ext3、ext4、vfat、fat32file file name : Check the type of file
a) a).elf Executable file type
b) b).c
c) c).txtrm-f: Mandatory deletion , If the file does not exist, it will be deleted .
cat file name : Output the contents of the file to the terminal .
Cat-n file name : Output the file content and line number to the terminal .head file name : Before the default output file content 10 That's ok
head-num file name : Put the file in front of num Output the line content to the terminal .tail file name : The default output file is the last 10 That's ok
tail-num file name : After the file num Output the line content to the terminal .Hard and soft links
Hard links : Through documents inode Link created on . Hard linked files cannot cross file systems .
command :in file name Link file nameSoft connection : Links created through absolute paths , As long as you can find the corresponding file in this path , Links work , Equivalent to creating hyperlinks .
command :in -s file name Link file name
characteristic :If the target file name of the hard link is modified , The link is still valid .
If you modify the target file name of the soft link , The connection is broken .
Move or delete an existing connection file , May cause link disconnection . If after deleting the target file , Recreate a file with the same name , Soft links will be restored , Hard links are no longer valid , Because the file is inode Has been changed .
Decompress and compress
gzip and gunzip
a) characteristic :Only a single ordinary file can be compressed or decompressed .
Cannot archive , The source file does not exist after compression or decompression .
After compression, the production compression format is .gz Format .
b) Compress :gzip file name
c) decompression :gunzip file name .gzBzip2 and bunzip2( Features and gzip be similar )
a) The compressed format is :.bz2
b) Compress :bzip2 file name
c) decompression :bunzip2 file name .bz2zip and unzip
a) zip function :zip The command is used to compress one or more files into a single compressed file
b) zip Format :zip Compressed file name List of files to compress
c) unzip function :unzip The command is used to put zip Decompress the compressed file
d) unzip Format :unzip Compressed file to unzip .
Be careful :
a) With archiving function , And compress
b) You can compress the folder , The suffix is .zip. Compressed folders need to be added -r.
c) The source file still exists after compression or decompressionxz and unxz( Features and gzip be similar )
a) The compressed format is :.xz form
b) Compress :xz file name .xz
c) decompression :unxz file name .xzTar
Options :
a) -x: Release archive
b) -c: Create a new archive
c) -v: Display the process information of archiving and release
d) -f: The user specifies the file name of the archive file , Otherwise, use the default name , Followed by the filename .
e) -j: from tar Generate archive , Then from bzip2 Compress
f) -z: from tar Generate archive , Then from gzip
g) -J from tar Generate archive , Then from xz CompressBe careful :
a) With archiving function , And it can be compressed or decompressed through parameters
b) The source file exists after compression or decompression
c) You need to write a fully compressed or decompressed file nameFormat :tar Options Compress ( decompression ) file name [ List of files to compress ]
Combine :
a) -cjf: With bz2 Compressed file in the format of
b) -czf: With gz Compressed file in the format of
c) -cJF: With xz Compressed file in the format of
Be careful :
jz stay f front : The compressed source file still exists
d)-xvf: Decompress a compressed package : The compressed package still exists after decompression .Shell Script
Essence and characteristics
a) shell The essence of a script is an ordered set of commands .
b) shell Script programming is an interpretive language , No compilation required .
c) shell scripting , It is to realize some functions through certain logical order .
d) shell The suffix of the script file .shThe steps of writing a script file
a) Create a script file :touch xxx.sh
b) Modify the script file permissions to executable
Chmod 777 xxx.sh
c) Edit script content :vi xxx.sh
d) Execute script file :./xxx.sh or bash xxx.shShell Variable
Allows users to create variables to store data , But it doesn't support data types
Format : Variable name = value ( Be careful : There can be no spaces on the left and right sides of the equal sign )
Classification of variables
a) User defined variables
b) Position variables or command line parameters$0 Executed script
$1-$9
${10} - ${N}
$# Calculate the number of command line parameters except the execution script file
[email protected] $* Traverse all the command line contents except the script file
c) Predefined variables$? The result of the execution of the previous command 0: really ; Not 0: false .
$$ process pid
d) environment variableShell The statement in
Declarative statements
a) With # Start to end of the line , Not interpreted to perform
b) #!/bin/bash Tell the operating system what type of shell Execute this script file .Functional statement : Any of the shell command 、 User program or other cx
Structural statements : Conditional test statements 、 Multiple branch statement 、 Loop statement 、 Loop control statement .
Functional statement
read( similar C Linguistic scanf- Input from terminal )
Format :read var1 var2 var3
Assign the first word read into the line to var1, The second is assigned to var2, And so on .
Read-p “ character string ” Variable list : You can print out strings , And input from the terminal .expr Arithmetic operation command expr It is mainly used for simple integer operation , Include : Add 、 reduce 、 ride 、 Divide and modulo
Be careful :
a) There must be spaces on the left and right sides of the operator
b) * and () You must add an escape character ,*、()
c) Expr Statement can directly output the operation resultlet The assignment operation
a) There must be no spaces in the operation
b) The result of the operation needs to be assigned to a variable
c) Variables participate in the operation process without adding $ ValueTest sentence :test Statement can test three objects : character string 、 Integers 、 File attribute
String test
a) s1=s2 Test whether the contents of two strings are exactly the same
b) s1!=s2 Test whether the contents of two strings are different
c) -z s1 test s1 Is the length of the string 0
d) -n s1 test s1 Whether the length of the string is not 0Integer test
a) a -eq b test a And b Whether it is equal or not
b) a -ne b test a And b Is it unequal
c) a -gt b test a Is it greater than b
d) a -ge b test a Greater than or equal to b
e) a -lt b test a Is less than b
f) a -le b test a Less than or equal to bTesting of file attributes
a) -d name test name Whether it is a directory
b) -f name test name Is it a common document
c) -e name Test whether the file existsShell Structural statements in
if……then……fi sentence
a) The basic structure :
If expression
Then
Command table
Fi
b) Hierarchical structure :
If expression
Then
Command table 1
Else
Command table 2
Fi
c) Nested structure :
If expression
Then
Command table 1
Else
If expression
Then
Command table
Fi
Fi
d) elif
if expression 1
then
Command table 1
Elif expression 2
Then
Command table 2
Elif expression 3
Then
Command table 3
……
Else
Command table n
Fi
Be careful : If the expression is true , Execute the commands in the command table ; Otherwise quit if sentence , The perform fi Subsequent statements .
if and fi Is a statement bracket for a conditional statement , Must be used in pairs ; The command in the command table can be a , It can also be several .case sentence
Format :
Case String variable in
Pattern 1)
Command table 1
;;
Pattern 2)
Command table 2
;;
……
Pattern n)
Command table n
;;
Esac
Be careful :
a) case Statement can only detect string variables
b) The command table ends with a single double quotation line , sign out case sentence
c) Pattern n Often written as characters * Represents all other modes
d) Case There can be multiple patterns in the match , Between each mode | separate .For……do……done Circular format :
For Variable name in Word list
Do
Command table
Done
Be careful :The variable takes each word in the word list in turn , Every time you take a word , Just do it once .
Commands in the loop body , The number of cycles is determined by the number of words in the word list .
The command in the command table can be a , It can also be multiple lines separated by semicolons or line breaks .
For Several writing formats of sentencesfor I in 1 2 3 4 do……done: Variable i Take values from the word list
for I do……done Variable i Take values from the command line , It can be omitted in Word list
for I in{1…10} do……done: Variable i from 1-10 Take value from the number
for((i=0;i<10;i++)) do……done The writing format is similar to C Language
While loop
Format :
While Command or expression
Do
Command table
Done
Be careful :while Statement first tests the value of a subsequent command or expression , If it is true , Just execute the command in the loop body once , Then test the value of the command or expression , Execution loop body , Exit the loop until the command or expression is false .Until loop
Format :
Until Command or expression
Do
Command table
Done
Be careful :until Circulation and while The function of the loop is similar , The difference is that only when the value of the tested command or expression is false , To execute the command table in the loop body , Otherwise exit the loop , This is related to while The order is just the opposite .Loop control statement :break And continue
Break: End this cycle
Break n: Jump out of n Once circulates
Continue: End this cycle and continue the next cycle
Continue n: Go to recent n Once on the next round of the loop statement .Shell Array
Array definition and initialization
a) arr=(v1 v2 v3 v4)
b) arr=($1 $2 $3 4 ) c ) r e a d a b c a r r = ( 4) c) read a b c arr=( 4)c)readabcarr=(a $b $c)
d) read -a Array nameAccess array
a) Take an element of the array : Count Group name [ Next mark ] 0 b ) Yes Count Group element plain Of value Into the That's ok repair Change : Count Group name [ Next mark ] = value c ) All over calendar Count Group : { Array name [ Subscript ]} 0 b) Modify the value of the array element : Array name [ Subscript ]= value c) Traversal array : Count Group name [ Next mark ]0b) Yes Count Group element plain Of value Into the That's ok repair Change : Count Group name [ Next mark ]= value c) All over calendar Count Group :{ Array name [@]}
d) Get the number of array elements :${# Array name [@]}
边栏推荐
- 利用or-tools来求解路径规划问题(VRP)
- 【AUTOSAR之FEE(非易失存储器Flash与Eeprom区别)】
- Lvgl8.1 version notes
- 【存储器了解 RAM flash和eeprom存储器的区别和作用】
- Review of basic principles of steel structure
- 钢结构基本原理全面详细总结
- The green data center "counting from the east to the west" was fully launched
- 高分子物理名词解释归纳
- Practical convolution correlation trick
- Green data center: comprehensive analysis of air-cooled GPU server and water-cooled GPU server
猜你喜欢

Using pycaret: low code, automated machine learning framework to solve regression problems

Data mining scenario - false invoice

Use steps of Charles' packet capturing

把LVGL所有控件整合到一个工程中展示(LVGL6.0版本)

高等代数知识结构

NVIDIA NVIDIA released H100 GPU, and the water-cooled server is adapted on the road

时间序列的数据分析(三):经典时间序列分解

【AUTOSAR DCM 1.模块简介(DSL,DSD,DSP)】

ARM架构与编程4--串口(基于百问网ARM架构与编程教程视频)

Installation and use of APP automated testing tool appium
随机推荐
钢结构复习题
ARM架构与编程4--串口(基于百问网ARM架构与编程教程视频)
Smart pointer shared_ PTR and unique_ ptr
Hardware knowledge 1 -- Schematic diagram and interface type (based on Baiwen hardware operation Daquan video tutorial)
高电压技术复习资料
【AUTOSAR COM 3.信号的收发流程TX/RX】
【AUTOSAR CanTP 1.学习UDS诊断的网络层协议】
NLP natural language processing - Introduction to machine learning and natural language processing (2)
C语言小项目——学生成绩管理系统
【AUTOSAR COM 2.通信协议栈进阶介绍】
博客搭建四:将自己的博客加入百度和谷歌收录的方法
obs插件基础
Using or tools to solve path planning problem (VRP)
【AUTOSAR COM 4.Com服务层模块的介绍】
高电压技术考题附答案
A comprehensive and detailed summary of the basic principles of steel structure
输入三角形边长,求面积
钢结构基本原理复习
【AUTOSAR COM 1.通信协议栈介绍】
Summary of problems encountered during app audit