One article they get dry Linux system development ---

First out about Linux system development to master knowledge, the follow-up article will explain one by one.
I welcome attention to the micro-channel public number: fensnote

What Linux system development will be used?

C programming language

Linux kernel is written in C, so, Linux system development may deal with many systems API, we need to master the C programming language, C language is the most basic Linux development language, of course, you can also use C ++. Generally do when interacting with the system modules, more with C language, do the top business applications, in order to develop efficient, will use C ++ to develop, after all, C ++ is an object-oriented development language, suitable for the development of large-scale projects to facilitate modular, code reuse rate.

shell script

shell script, that is, using a series of commands under Linux systems, organic combination together, and to complete its intended function. Linux design philosophy is "small is beautiful" and this idea is the perfect embodiment of shell scripting. Each command completes only one function, different commands together, but they can implement complicated functions. Do under Linux development, will inevitably have to deal with (such as testing, analysis, data, etc.) with the script.

Slowly learn to use Makefile

Makefile is essential when managing Linux application developers to compile scripts, this is also a lot of things inside, but the beginning may look simple, enough on the line, along with bigger and bigger the project, the code is more complex files and directories, this time the Makefile might complicated, involves a different directory Makefile call or coordinated.
Such as embedded systems, usually more than one application, there may be more than one program, the overall compile time, will include the following:

  1. Compile each application module (need to determine whether the compilation is successful, the situation appears to stop compilation fails, throw an error message)
  2. Application packaging (compressed or made partition image)
  3. The default configuration file packaging
  4. the uboot, kernel, file system, application integrally packaged into an image file, the size of the corresponding flash partition size (less than the size of the dummy data needs to be filled, and to ensure that the corresponding partition).
  5. Automatic version management, the compilation is complete, the package is complete, the version numbers can be automatically generated based on time by the script.

These things done is actually quite complex, requiring complete with shell scripts and Makefile.

What are the general Linux system programming knowledge? What are common? What is not commonly used?

General Linux programming knowledge

File IO

More commonly used
Linux system, all the resources are in the form of access to the file, devices are abstracted to device files, placed in the / dev directory.
The basic access functions:

Function name Brief introduction How to use general
open Open the device file Access device file, first of all to open the device
close Turn off the device file After the file access, you need to call this interface, if not closed, it will make fb exhausted
read Read data Reading data, the content may be a text file, the camera may be a data
write data input Writing data to a device, such as serial communication, write data may be transmitted
ioctl IO operation function This function is more functional, known as the glove compartment - can read and write data, the students should do drive very understanding
fcntl Property setters Already open device, setting properties, such as the serial port may be provided for reading data blocking and non-blocking properties
lseek Changing the offset amount It is generally used to modify the offset open position to read and write files
File and directory operations

Common
access system programming and ultimately, files and directories, such as the file you want to read all the names in a directory, or modify the file name, change directories, move files, and so on.

Function name Brief introduction How to use general
stat、 fstat 、lstat Get File Status It can get to create the file, access time, file size, etc.
access Detect file attributes Commonly used to determine whether a file exists
chmod Modify file permissions Generally when it comes to file access permissions modification, it will be used, such as adding executable permissions
mkdir Create a directory Generally in the program is judged to need to use the directory does not exist, create with this function
rmdir Remove directory In case you need to delete a directory, seldom used
opendir open Directory Before reading the catalog information, you need to open the catalog (class access to the file)
readdir Read the directory contents In the retrieve files will be used, read the directory under the file list
closedir Close Contents After reading is complete, remember to close the catalog
sync Synchronize data to disk This function is generally modified files, write data calls, let the system to synchronize data to disk
Standard IO Libraries

More commonly
called the standard IO library, in fact, the C language file IO, IO and another front there's a reference to " File IO " There is a difference in reading and writing files, the standard IO is cached, and Linux systems the file IO functions are not cached.
The main file manipulation functions:

Function name Brief introduction How to use general
fopen open a file Put the file before the first call to get the file handle fopen
fclose Close the file After the file access, remember to close the file, or cause a memory leak
fread Read the file Reads the file data
fseek Modify the file read and write position For modifying the position of read and write file offset
Process Control

General
multi-process programming if you do not use it, this one probably is not much use, my code is not used too much.
The main point is the process of knowledge creation, child process management, process exit resources release, and so on.

Threaded programming

More commonly used
on the system, the general run of the task will be more and more threads are more commonly used, can generally be divided into two types, one is the long-running tasks, one is executing the task on their own exit. Now has support for C ++ 11 threads, very convenient to use. C ++ 11 not previously when used for convenience, are clusters of pthrea_ secondary packaging function.

Advanced IO

Common
may be more you wonder why so many " IO " related things: file IO, standard file IO, senior IO!
Yes, there are more IO, the first two " IO " a little bit similar to the previous two senior IO bit different.
Advanced IO IO was mainly about the operation mode: blocking, non-blocking control, the most important is to realize IO multiplexing by select and poll, asynchronous execution so the program can be achieved. Now with more of Nginx, epoll model is used to achieve high concurrency.

Interprocess communication

Very common
in general linux system below, since it is the system, then more than one application is running, and that multiple applications will require data interactively, then, to use the inter-process communication, interprocess communication, there are many open source tools ( For example DBUS), briefly outline the communication systems provided:

name Brief introduction
pipeline Generally used for communication between parent and child, named pipes across program
message queue Type message queue can be classified, for small amounts of data, the communication simple
signal PV operation for synchronization, and can be used with shared memory used, data is written to tell another thread can read
Shared memory For large amount of data transmission
socket socke Not only is the interface of network communication, can also be a local interprocess communication (UNIX socke), this approach is common
database

Common
If you are storing configuration parameters, I do not recommend using a database with json quite good. Storing data is typically used for data comparison rules, so that data easy to manage. In embedded systems, with more of a sqlite database.

Serial Programming

More commonly used
in Linux, especially for embedded systems, this may be unavoidable, more commonly used. In fact, serial programming is also very simple, it may be 200 lines of code to the serial communication established. Data communication application layer is to use write, and read operations function, but if you want to do a bit better, we need to take the time to do a software framework, such as the use of select previously mentioned asynchronous operation (will explain later in this article and serial implementation of the package).

network programming

Super commonly
believed now embedded devices basically need a network communication function, so the network programming is naturally very popular. Special equipment is now the development of things, all things Internet. Network programming under Linux, there is a range of API functions, with a lot of configuration parameters will be more, the beginning can be very stressful, I do not know what the value of which parameter settings appropriate (we are slowly try out trial and error ). This do not worry, I will share with you later I came out with a C ++ library packaged network communications, including TCP, UPD, UDP multicast domain sockets (local) etc. packages.

Conclusion

Follow prepared in accordance with the contents of these items listed today, in a later article we introduced one by one, welcome attention to follow-up.

Micro-channel public number:
Here Insert Picture Description

Published 51 original articles · won praise 49 · views 50000 +

Guess you like

Origin blog.csdn.net/wuquan_1230/article/details/104808817