Disclosure of Invention
The invention mainly aims to provide a file generation method, an intelligent terminal and a storage medium, and aims to solve the problem that a coredump file with a large memory is inconvenient to store, copy and use in the prior art.
In order to achieve the above object, the present invention provides a file generating method, including the steps of:
when a first thread in a plurality of threads in the user program executes an error instruction, the user program triggers a CPU (Central processing Unit) to interrupt so as to execute an interrupt program;
the interrupt program searches and records a first thread executing the wrong instruction;
the Linux operating system sends an event that the user program executes an error instruction and the ID of the first thread to the user program;
and the user program stores the data in the memory address area used by the first thread to a core dump file according to the ID of the first thread.
Optionally, in the file generation method, the user program is composed of a plurality of independent threads.
Optionally, in the file generation method, each thread uses an independent memory address area.
Optionally, in the file generating method, the interrupt program is used to control the CPU to stop executing the normal code of the program, and jump to execute the code for processing the current emergency.
Optionally, in the file generating method, the error instruction includes an instruction that an error parameter is input.
Optionally, the file generating method further includes:
when a first thread in a plurality of threads in a user program executes an error instruction, the Linux operating system does not directly trigger generation of a core dump file any more.
In addition, to achieve the above object, the present invention further provides an intelligent terminal, wherein the intelligent terminal includes: a memory, a processor and a file generation program stored on the memory and executable on the processor, the file generation program when executed by the processor implementing the steps of the file generation method as described above.
In order to achieve the above object, the present invention further provides a storage medium storing a file generation program that realizes the steps of the file generation method described above when executed by a processor.
In the invention, when a first thread in a plurality of threads in a user program executes an error instruction, the user program triggers a CPU (Central processing Unit) to interrupt so as to execute an interrupt program; the interrupt program searches and records a first thread executing the wrong instruction; the Linux operating system sends an event that the user program executes an error instruction and the ID of the first thread to the user program; and the user program stores the data in the memory address area used by the first thread to a core dump file according to the ID of the first thread. The invention only generates the corresponding core dump file for the thread executing the error instruction, thereby greatly reducing the size of the core dump file and facilitating the storage, the copying and the use of the core dump file.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention clearer and clearer, the present invention is further described in detail below with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
As shown in fig. 1, the file generation method according to the preferred embodiment of the present invention includes the following steps:
step S10, when the first thread of the plurality of threads in the user program executes the error instruction, the user program triggers the CPU to interrupt to execute the interrupt program.
Specifically, the user program can run a plurality of threads (a thread is the minimum unit of operation scheduling of an operating system, is contained in a process and is the actual operation unit in the process, one thread refers to a single-sequence control flow in the process, a plurality of threads can be concurrently executed in one process, each thread executes different tasks in parallel, the advantage of multi-thread program design on a multi-core or multi-CPU or a CPU supporting Hyper-threading is obvious, namely the execution throughput rate of the program is improved, a multithreading technology is used on a single-CPU and single-core computer, the part which is in charge of I/O processing and human-computer interaction and is usually blocked in the process can be separated from the part of intensive calculation, a special work thread is written to execute the intensive calculation, and the execution efficiency of the program is improved), and the user program consists of a plurality of independent threads.
The first thread refers to one of the threads (which may be any one of the threads), that is, when a thread of the user program executes an error instruction, the CPU is triggered to interrupt, and an interrupt program is executed (also referred to as an interrupt service program, where a processor processes a "panic" which is understood to be a service that is completed by executing a specific program programmed in advance, the program processing the "panic" is referred to as an interrupt service program, when the CPU is processing internal data, an emergency occurs outside, the CPU is required to suspend the current work to process the emergency, and after the processing is completed, the CPU returns to the original interrupted address to continue the original work, and such a process is referred to as interrupt).
The interrupt program is used for controlling the CPU to stop executing the normal codes of the program, skipping to execute the codes for processing the current emergency condition, namely when some emergency condition occurs (for example, the error instruction is executed), the CPU stops executing the normal codes of the program, and skipping to execute the codes for processing the emergency condition.
Wherein the error instruction comprises an instruction into which an error parameter is input. For example, the memory has 8Gbyte, the address range is 0-8Gbyte, if a certain command reads the data of the memory with the memory address of 9Gbyte, this is an erroneous command, and the blue screen of the windows system is often caused by the erroneous command.
Step S20, the interrupt program searches for the first thread executing the faulty instruction and records the first thread.
Specifically, when the user program triggers the CPU interrupt, and after the interrupt program is executed, the interrupt program searches for a first thread (i.e., a certain thread that executes the wrong instruction) that executes the wrong instruction and records the first thread.
In step S30, the Linux operating system sends the user program an event that the user program executed the error instruction and the ID of the first thread to the user program.
Specifically, the Linux operating system (a multi-user, multi-task and multi-CPU supporting operating system based on POSIX and Unix; Linux is not only stable in system performance but also open source software; the core firewall component of the Linux is efficient in performance and simple in configuration, and the safety of the system is guaranteed; in many enterprise networks, in order to pursue speed and safety, Linux is used as a server by network operation and maintenance personnel, and can be used as a server and a network firewall, and the Linux sends an event that a user program executes an incorrect instruction and the ID of the thread (namely, the ID can identify which thread the user program executes) to the user program, wherein each thread corresponds to a special ID.
In step S40, the user program saves the data in the memory address area used by the first thread to the core dump file according to the ID of the first thread.
Specifically, the user program saves, according to the thread ID (i.e., a thread that executed an erroneous instruction), only data in a memory address area (each thread uses a separate memory address area) used by the thread (i.e., a thread that executed an erroneous instruction) to the core dump file (i.e., the coredump file). Further, when a plurality of threads execute wrong instructions, the steps are executed one by one according to the sequence.
The Linux operating system sends the event that the user program executes the wrong instruction and the thread ID to the user program, and because only the user program knows which memory addresses are used when the thread runs, the user program only saves the data of the memory addresses used by the thread to a coredump file.
For example, the user program creates 10 threads, thread 1, thread 2, thread 3, thread 4, thread 5, thread 6, thread 7, thread 8, thread 9,thread 10. Each thread uses an independent memory address area 1, a memory address area 2, a memory address area 3, a memory address area 4, a memory address area 5, a memory address area 6, a memory address area 7, a memory address area 8, a memory address area 9 and amemory address area 10, and one thread corresponds to one memory address area. When thread 2 executes an error instruction, the Linux operating system sends an event that the user program executes the error instruction and the ID of the thread 2 to the user program, and the user program only saves the data in the memory address area 2 used by the thread 2 to a coredump file (i.e., a core dump file).
The invention generates a simplified coredump file, when a certain thread of a user program executes an error instruction, a Linux operating system does not directly trigger the generation of the coredump file (the Linux operating system cannot distinguish which data are data which cannot be used by the thread and only can store all data of a brain), but finds out the thread ID executing the error instruction, transmits an event executing the error instruction and the thread ID to the user program for processing, and the user program only stores data in a memory address area used by the thread into the coredump file according to the thread ID.
Further, as shown in fig. 2, based on the file generation method, the present invention also provides an intelligent terminal, which includes aprocessor 10, amemory 20 and adisplay 30. Fig. 2 shows only some of the components of the smart terminal, but it is to be understood that not all of the shown components are required to be implemented, and that more or fewer components may be implemented instead.
Thememory 20 may be an internal storage unit of the intelligent terminal in some embodiments, such as a hard disk or a memory of the intelligent terminal. Thememory 20 may also be an external storage device of the Smart terminal in other embodiments, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like, which are provided on the Smart terminal. Further, thememory 20 may also include both an internal storage unit and an external storage device of the smart terminal. Thememory 20 is used for storing application software installed in the intelligent terminal and various data, such as program codes of the installed intelligent terminal. Thememory 20 may also be used to temporarily store data that has been output or is to be output. In one embodiment, thememory 20 stores afile generation program 40, and thefile generation program 40 can be executed by theprocessor 10 to implement the file generation method of the present application.
Theprocessor 10 may be, in some embodiments, a Central Processing Unit (CPU), a microprocessor or other file generation chip, and is used for executing program codes stored in thememory 20 or processing data, such as executing the file generation method.
Thedisplay 30 may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an OLED (Organic Light-Emitting Diode) touch panel, or the like in some embodiments. Thedisplay 30 is used for displaying information at the intelligent terminal and for displaying a visual user interface. The components 10-30 of the intelligent terminal communicate with each other via a system bus.
In one embodiment, the following steps are implemented when theprocessor 10 executes thefile generation program 40 in the memory 20:
when a first thread in a plurality of threads in the user program executes an error instruction, the user program triggers a CPU (Central processing Unit) to interrupt so as to execute an interrupt program;
the interrupt program searches and records a first thread executing the wrong instruction;
the Linux operating system sends an event that the user program executes an error instruction and the ID of the first thread to the user program;
and the user program stores the data in the memory address area used by the first thread to a core dump file according to the ID of the first thread.
The user program is composed of a plurality of independent threads.
Each thread uses a separate memory address region.
The interrupt program is used for controlling the CPU to stop executing the normal codes of the program and jump to execute the codes for processing the current emergency condition.
The error instruction includes an instruction that an error parameter is input.
The file generation method further comprises:
when a first thread in a plurality of threads in a user program executes an error instruction, the Linux operating system does not directly trigger generation of a core dump file any more.
The present invention also provides a storage medium, wherein the storage medium stores a file generation program, and the file generation program realizes the steps of the file generation method when being executed by a processor.
In summary, the present invention provides a file generating method, an intelligent terminal and a storage medium, where the method includes: when a first thread in a plurality of threads in the user program executes an error instruction, the user program triggers a CPU (Central processing Unit) to interrupt so as to execute an interrupt program; the interrupt program searches and records a first thread executing the wrong instruction; the Linux operating system sends an event that the user program executes an error instruction and the ID of the first thread to the user program; and the user program stores the data in the memory address area used by the first thread to a core dump file according to the ID of the first thread. The invention only generates the corresponding core dump file for the thread executing the error instruction, thereby greatly reducing the size of the core dump file and facilitating the storage, the copying and the use of the core dump file.
Of course, it will be understood by those skilled in the art that all or part of the processes of the methods of the above embodiments may be implemented by a computer program instructing relevant hardware (such as a processor, a controller, etc.), and the program may be stored in a computer readable storage medium, and when executed, the program may include the processes of the above method embodiments. The storage medium may be a memory, a magnetic disk, an optical disk, etc.
It is to be understood that the invention is not limited to the examples described above, but that modifications and variations may be effected thereto by those of ordinary skill in the art in light of the foregoing description, and that all such modifications and variations are intended to be within the scope of the invention as defined by the appended claims.