Method and system for executing command by embedded system function

By initializing a parent process and forking a child process to a background server with minimal resource usage, the method and system address the instability of embedded Linux systems by ensuring successful command execution and reducing hardware costs.

CN119225864APending Publication Date: 2024-12-31广州思林杰科技股份有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411103813.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-13
Publication Date
2024-12-31

AI Technical Summary

Technical Problem

Embedded Linux systems face frequent failures in executing external commands due to insufficient system resources, which cannot be addressed by increasing hardware resources, leading to instability and high failure rates.

Method used

A method and system that initializes a parent process and forks a child process to a background server, occupying minimal resources, allowing the child process to execute external commands and return results to the parent, thereby reducing resource usage and ensuring command stability and minimizing hardware cost.

Benefits of technology

The method and system ensure the success of system stability by reducing the failure rate of system() calls, ensuring successful command execution even with limited resources, thus enhancing system reliability and saving hardware costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119225864A_ABST
    Figure CN119225864A_ABST
Patent Text Reader

Abstract

The invention discloses an embedded system function execution command method and system, and the method comprises the steps: initializing a parent process F, forming () a child process P, enabling the child process P to reside in a background server, enabling the resource occupied by the child process P to be smaller than N, and enabling the N to be larger than 0; and calling system (), transmitting the external command to the child process P, executing the external command in the child process P, and returning an execution result to the parent process F after the child process P executes the external command. According to the method, the child process P only needs a small part of resources to achieve the same result as previous system () calling, system () calling failure caused by insufficient resources is avoided, the system stability is guaranteed, invalid occupation of the resources is fundamentally avoided, and the system resources are reasonably utilized to the maximum extent.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of embedded Linux, and in particular to a method and system for executing commands of an embedded system function. Background Art

[0002] When executing external commands, embedded Linux programs generally use the system() function to call external commands, such as formatting a user partition: system(" / bin / mkfs.ext4 / dev / mmcblk0p7"). However, in the process of executing external commands, system() calls often fail. By analyzing the reasons for the failure, it is found that a large number of system() call failures are caused by insufficient system resources. In embedded systems, due to hardware cost reasons, the system hardware resources themselves are very limited, and the problem of call failure cannot be solved by increasing the system hardware resources. Therefore, reducing the failure rate of system() calls on limited embedded resources has become an urgent problem to be solved. Summary of the invention

[0003] The purpose of the present invention is to overcome the deficiencies of the above prior art and to provide a method and system for executing embedded system function commands which has high stability and can effectively save the hardware cost of the embedded system.

[0004] The purpose of the present invention is achieved through the following technical solutions: The first aspect of the present invention provides a method for executing commands using an embedded system function, the method comprising: initializing a parent process F, and forking () a child process P, placing the child process P on a background server, wherein the child process P occupies resources less than N, where N>0; calling system (), passing an external command to the child process P, executing the external command in the child process P, and returning the execution result to the parent process F after the child process P executes the external command.

[0005] Preferably, the method of executing commands of the embedded system function is encapsulated to replace the call of system().

[0006] Preferably, after the parent process F is initialized, the system resources occupied by the parent process F are less than M, where M>0.

[0007] The second aspect of the present invention provides an embedded system function execution command system, the system comprising: an initialization module, used to initialize a parent process F; a child process fork module, used to fork() a child process P, and make the child process P resident on a background server, the child process P occupies resources less than N, N>0; a system call module, used to call system(), pass an external command to the child process P, and the child process P executes the external command, and the child process P returns the execution result to the parent process F after executing the external command.

[0008] Preferably, the embedded system function execution command system further comprises: an encapsulation module, which is used to encapsulate the embedded system function execution command method to replace the call of system().

[0009] The present invention has the following advantages over the prior art: When the present invention initializes the parent process F, the child process P is forked(), and the parent process F only occupies a small number of system resources, and the forked child process P will also occupy very small number of system resources. The child process P only needs a small part of the resources to achieve the same result as the previous system() call, and the system() call will not fail due to insufficient resources. The successful creation of the child process P also guarantees the success rate of subsequent external command calls, avoiding the possibility of failure before modification, thereby greatly improving the reliability of system command calls, improving the stability of products, and effectively saving the hardware cost of embedded systems. BRIEF DESCRIPTION OF THE DRAWINGS

[0010] The drawings constituting a part of the present application are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings: Figure 1 A schematic flow chart of a method for executing commands by an embedded system function of the present invention.

[0011] Figure 2 A flowchart of executing commands for an existing embedded system function.

[0012] Figure 3 It is a flowchart of the embedded system function execution command of the present invention. DETAILED DESCRIPTION

[0013] The present invention will be further described below in conjunction with the accompanying drawings and embodiments.

[0014] Figure 1A schematic flow chart of a method for executing commands by an embedded system function of the present invention. Figure 3 This is a flowchart of the embedded system function execution command of the present invention. Figure 1 and Figure 3 , a method for executing a command in an embedded system function includes: S1, initialize the parent process F, and fork() the child process P, and make the child process P reside on the background server. The resource occupied by the child process P is less than N, N>0; S2, calls system() to pass the external command to the child process P, and the child process P executes the external command. After the child process P executes the external command, the execution result is returned to the parent process F.

[0015] In this embodiment, the method of executing commands of the embedded system function is encapsulated to replace the call of system().

[0016] In this embodiment, after the parent process F is initialized, the system resources occupied by the parent process F are very few (less than M, M>0). For example, the system resources occupied by the parent process F include 0.1MB of memory and 2 file descriptors.

[0017] By analyzing the execution process of system(), we can see that Figure 3, the execution process of system() calling external commands is as follows: when system() is called, the embedded system creates a child process copy P through fork(). Fork will copy the status of the current process (parent process F), including memory, file descriptors, etc., create a new process (child process P), and then use the exec() system call in the child process P to execute the specified external command. The exec() system call will load a new program into the memory space of the child process P, replacing the original program. This new program is the command passed to system(), such as " / bin / mkfs.ext4" mentioned earlier. Then the parent process F waits for the child process P to finish executing the command. In this process, fork() is used to copy the process and create a new child process P, and exec() is used to load and execute external commands. Due to the mechanism of fork(), the child process is a copy of the calling process (parent process F) and has the same code, data, file descriptors, environment, etc. If the parent process F that calls system() itself uses more system resources because of its long running time and many tasks, the external command called through system() will fail to execute due to insufficient system resources caused by the fork() copy operation. For example, after the parent process F has been running for a period of time, it has used 20MB of memory and 100 file descriptors. When executing the fork() operation, the child process P will also use up a considerable amount of system resources of the parent process. If the remaining resources of the system are not enough to fill so many resource allocations at this time, this system() call will definitely fail. However, this application avoids the situation where fork() requires more system resources. This application forks the child process P when the parent process F is initialized. At this time, since the parent process F has not yet processed the task business logic, there is no problem of long-term operation. It only occupies a small amount of system initialization resources (the system resources occupied by the parent process F are less than M, M>0), such as 0.1MB of memory and 2 file descriptors. At this time, the fork() child process P will also occupy very few system resources (also only occupying 0.1MB of memory and 2 file descriptors), and then the child process P that occupies very few resources (the child process P occupies less than N, N>0) from the fork() will be stationed in the background. When the system() call is needed, the external command parameters will be passed to the child process P for execution. After the child process P completes the command, the result will be returned to the parent process. Figure 2 A flowchart of executing commands for an existing embedded system function. Figure 3 This is a flowchart of the embedded system function execution command of the present invention. Figure 2 and Figure 3 contrast, Figure 3 Highlight a little fork logic and Figure 2The difference between the two processes is that due to the low system resource usage, there will be no failure here.

[0018] It can be seen that the child process P only needs a small amount of resources to achieve the same result as the previous system() call, and the system() call will not fail due to insufficient resources. When the parent process F is initialized, the child process P is forked(). Since the resource usage is very low during initialization, there is no problem of creation failure due to insufficient resources, which also ensures that the child process P will be created successfully. The successful creation of the child process P also guarantees the success rate of subsequent external command calls, avoiding the possibility of failure before modification, thereby greatly improving the reliability of system command calls and improving product stability.

[0019] In summary, the present application can solve the problem of system() call failure due to insufficient resources in embedded systems, thereby ensuring that embedded devices do not need to be frequently restarted due to long running time or many operating tasks. The present application is particularly useful in situations where some devices cannot be restarted. The present application can also solve the problem of choosing to increase hardware resources in order to ensure system stability, which can effectively save the hardware cost of embedded systems. In addition, the present application cleverly uses the design logic of modifying the system() call to solve the problem of failure. The principle is to fundamentally avoid the ineffective occupation of resources and maximize the rational use of system resources.

[0020] An embedded system function execution command system applicable to the above-mentioned embedded system function execution command method includes: an initialization module, used to initialize the parent process F; a child process fork module, used to fork() the child process P, and make the child process P resident on the background server, and the resources occupied by the child process P are less than N, N>0; a system call module, used to call system(), pass the external command to the child process P, and the child process P executes the external command. After the child process P executes the external command, the execution result is returned to the parent process F.

[0021] In this embodiment, the embedded system function execution command system further includes: an encapsulation module, which is used to encapsulate the embedded system function execution command method to replace the call of system().

[0022] This application proposes a solution to the failure of embedded system system() to execute external commands, which can reduce a very common product phenomenon, that is, many devices suddenly fail to operate partially after being used for a period of time, and the device can only be restored after restarting. This application can greatly reduce the occurrence of this problem and has a great effect on improving the stability of embedded products. This application can also solve the problem of choosing to increase hardware resources in part to ensure system stability, which can effectively save the hardware cost of embedded systems. In addition, this application cleverly uses the design logic of modifying the system() call to solve the problem of failure. The principle is to fundamentally avoid the ineffective occupation of resources and maximize the rational use of system resources.

[0023] The above specific implementation modes are preferred embodiments of the present invention and cannot be used to limit the present invention. Any other changes or other equivalent replacement methods that do not deviate from the technical solution of the present invention are included in the protection scope of the present invention.

Claims

1. A method for executing a command of an embedded system function, characterized in that: include: Initialize the parent process F, fork() the child process P, and keep the child process P in the background server. The resource occupied by the child process P is less than N, where N>0; Call system() to pass the external command to the child process P, and the child process P executes the external command. After the child process P executes the external command, the execution result is returned to the parent process F.

2. The method for executing an embedded system function command according to claim 1, characterized in that: The method of executing commands of the embedded system function is encapsulated to replace the call of system().

3. The method for executing an embedded system function command according to claim 1, characterized in that: After initializing the parent process F, the system resources occupied by the parent process F are less than M, M>0.

4. A system for executing commands using an embedded system function, characterized in that: include: Initialization module, used to initialize the parent process F; The child process fork module is used to fork() the child process P, and make the child process P resident on the background server. The resource occupied by the child process P is less than N, N>0; The system call module is used to call system() to pass the external command to the child process P, and the child process P executes the external command. After the child process P executes the external command, the execution result is returned to the parent process F.

5. The system for executing embedded system function commands according to claim 4, characterized in that: Also includes: The encapsulation module is used to encapsulate the method of executing commands of the embedded system function to replace the call of system().