A method and system for constructing and monitoring a role-based multi-task software system
Through the role-based multi-task software system construction method and monitoring method, the internal structure and call relationship of the system are clarified, and the sub-task status is monitored in real time, solving the complicated and complex monitoring problems in the existing technology, and achieving efficient fault location and resource management.
Patent Information
- Application Number
- CN202411200194.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-29
- Publication Date
- 2025-08-08
- Estimated Expiration
- 2044-08-29
AI Technical Summary
Due to the unclear structure and call relationship of existing multi-tasks, the existing multi-task software system cannot grasp the status of all subtasks in real time, making it difficult to judge whether the system is operating normally, and the monitoring process is complicated and complicated, so it is impossible to quickly discover exceptions and positioning problems.
The role-based multi-task software system construction method is adopted, and the resource role and task role are started through role 1, the role tree is built, the call relationship within the system is clarified, and the exception signal is monitored through role 1, and the call stack information is obtained for exception positioning.
Real-time status monitoring and abnormal positioning of multi-task software systems are realized, fault positioning efficiency and resource management capabilities are improved, system flexibility and scalability are enhanced, and monitoring process is simplified.
Smart Images

Figure CN119376874B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of multi-task software, and in particular to a construction and monitoring method and system of a role-based multi-task software system. Background Art
[0002] At present, multi-task software systems, especially robot multi-task software systems, need to support the autonomous execution of complex collaborative tasks under complex environmental conditions with uncertainty, such as autonomous collaborative perception, autonomous collaborative planning, autonomous collaborative control, and multi-machine autonomous collaboration. Multi-task software systems generally implement these functions as multiple decoupled modules to form several subtasks. During operation, dozens or even hundreds of concurrent processes or threads will be generated. Processes (threads) will be dynamically created and terminated according to factors such as environmental changes and capability requirements. However, the existing multi-task software systems are unable to grasp the status of all subtasks in real time due to their unclear structure and calling relationships, making it impossible to determine whether the system is operating normally.
[0003] Due to complex factors such as the uncertainty of the execution environment of multi-task software systems, the complexity of task coordination, and the increasing size of collaborative development teams, monitoring multi-task software systems presents significant challenges in terms of task management, fault location, and exception recovery. Existing monitoring processes for multi-task software systems include fault analysis and debugging tools. For example, the gdb debugging tool is often used to debug a single target program with potential anomalies. However, the difficulty in debugging multi-task software systems lies in the difficulty of debugging personnel in locating which task may have an anomaly. Furthermore, the execution flows generated by multiple concurrent processes (threads) are not always the same, meaning that the location of a system crash caused by the same bug may vary across multiple executions. Therefore, existing monitoring methods for multi-task software systems, which rely on checking the running status of each task process (thread) one by one, are cumbersome and complex, and cannot quickly detect anomalies and locate problems. Summary of the Invention
[0004] In order to solve the problem that the existing multi-task software system has unclear structure and calling relationship, resulting in the inability to grasp the status of all subtasks in real time, the present invention proposes a method for constructing a role-based multi-task software system, including:
[0005] Based on the multi-tasking software system startup instruction, start role No. 1;
[0006] Start the resource role through the No. 1 role, and the resource role is used to provide resource services for the task role;
[0007] Based on the acquired task process startup requirements, a resource access task is obtained, and a task role is started through the No. 1 role, and the task role is used to execute the resource access task;
[0008] The role No. 1 is taken as the root node, and the resource role and the task role are taken as descendant nodes to construct a role tree, thereby obtaining a role-based multi-task software system.
[0009] Optionally, starting the resource role through the No. 1 role includes:
[0010] Call the fork system call through the No. 1 role to create a startup child process;
[0011] By calling the execlp system call through the No. 1 role, the created startup child process is replaced with the resource role process;
[0012] The replaced startup sub-process is used to start the resource role.
[0013] Optionally, the task roles include a task process management role and a task behavior execution role;
[0014] Wherein, the task process management role is used to manage the task behavior execution role;
[0015] The task behavior execution role is used to execute the resource access task;
[0016] The step of starting the task role through the No. 1 role includes:
[0017] The task process management role is started through the No. 1 role, and the task behavior execution role is started through the task process management role.
[0018] Optionally, starting the task process management role through the No. 1 role includes:
[0019] The first role listens to the task flow startup requirement and calls the fork system call to create an initial child process;
[0020] By calling the execlp system call through the No. 1 role, the created initial child process is replaced with the task role management process;
[0021] The task flow management role is started by using the replaced initial sub-process.
[0022] Optionally, starting the task process management role through the No. 1 role includes:
[0023] Obtain the configuration file of role 1, read the configuration file through role 1, and call the fork system call to create a configuration child process;
[0024] By calling the execlp system call through the No. 1 role, the created configuration sub-process is replaced with the task flow management process;
[0025] The replaced startup sub-process is used to start the task flow management role.
[0026] Optionally, starting the task behavior execution role through the task process management role includes:
[0027] Based on the task process startup requirement, the role name of the task behavior execution role to be started and the task status of the resource access task are obtained;
[0028] According to the role name of the task behavior execution role to be started and the task status of the resource access task, the StartActor role startup interface is called by the task process management role to start the task behavior execution role corresponding to the role name.
[0029] Optionally, calling the StartActor role startup interface through the task process management role to start the task behavior execution role corresponding to the role name includes:
[0030] Call the StartActor role startup interface through the task process management role;
[0031] Reading the resource configuration file of the task behavior execution role through the resource role to obtain the requested resources required by the task behavior execution role when executing the resource access task; the resource configuration file includes: role name, requested resources and resource access mode;
[0032] The requested resources are allocated through the resource roles, and according to the result of the resource allocation, the task behavior execution role corresponding to the role name is started.
[0033] Optionally, allocating the requested resource according to the resource role includes:
[0034] Obtaining a resource access data table for the resource role; the resource access data table includes: a resource identifier, a resource name, a resource access mode, an access role list, and a health level attribute;
[0035] According to the resource access data table, a resource access mode corresponding to the requested resource is obtained; the resource access mode includes: resource sharing and resource exclusivity;
[0036] When the resource access mode corresponding to the requested resource is resource sharing, the role name of the task behavior execution role is added to the access role list of the resource access data table, and resource allocation is performed on the requested resource;
[0037] When the resource access mode corresponding to the requested resource is resource exclusive, check whether the access role list of the resource access data table is empty. If the access role list is not empty, add the role name of the task behavior execution role to the task role waiting queue; if the access role list is empty, allocate resources to the requested resource.
[0038] Optionally, starting the task behavior execution role corresponding to the role name according to the result of the resource allocation includes:
[0039] When the resource allocation result shows that the requested resource is successfully allocated, the task flow management role calls a fork system call to create an execution child process;
[0040] Calling the execlp system call through the task flow management role replaces the created execution sub-process with the process of the task behavior execution role;
[0041] The replaced execution sub-process is used to start the task behavior execution role corresponding to the role name.
[0042] Optionally, after starting the task behavior execution role corresponding to the role name, the method further includes:
[0043] According to the obtained role name of the task behavior execution role to be stopped, the StopActor role stop interface is called through the task flow management role to stop the task behavior execution role.
[0044] Optionally, calling a StopActor role stop interface by the task flow management role to stop the task behavior execution role includes:
[0045] Calling the StopActor role stop interface through the task process management role;
[0046] Reading the resource configuration file of the task behavior execution role to be stopped through the resource role to obtain the requested resources of the task behavior execution role to be stopped;
[0047] According to the resource access data table of the resource role, the resource access mode corresponding to the requested resource of the task behavior execution role to be stopped is obtained; when the resource access mode corresponding to the requested resource is resource exclusive, the to-be-released resource associated with the task behavior execution role to be stopped is obtained, and it is checked whether the task role waiting queue contains a task behavior execution role requesting the to-be-released resource; if so, the role name of the task behavior execution role is deleted from the task role waiting queue, and the task behavior execution role is started;
[0048] According to the resource access data table of the resource role, the role name of the task behavior execution role to be stopped is deleted from the access role list of the resource access data table; and a kill system call is called to stop the task behavior execution role.
[0049] Based on the same inventive concept, the present invention also provides a system for constructing a role-based multi-task software system, comprising:
[0050] Task startup module: used to start role 1 based on the multi-task software system startup instruction;
[0051] Resource management module: used to start the resource role through the No. 1 role, and the resource role is used to provide resource services for the task role;
[0052] Task management module: used to obtain resource access tasks based on the acquired task process startup requirements, start the task role through the No. 1 role, and the task role is used to execute the resource access tasks; use the No. 1 role as the root node and the task role as the descendant node to build a role tree to obtain a role-based multi-task software system.
[0053] Optionally, starting the resource role through the No. 1 role in the resource management module includes:
[0054] Call the fork system call through the No. 1 role to create a startup child process;
[0055] By calling the execlp system call through the No. 1 role, the created startup child process is replaced with the resource role process;
[0056] The replaced startup sub-process is used to start the resource role.
[0057] Optionally, the task roles in the task management module include a task process management role and a task behavior execution role;
[0058] Wherein, the task process management role is used to manage the task behavior execution role;
[0059] The task behavior execution role is used to execute the resource access task;
[0060] The step of starting the task role through the No. 1 role includes:
[0061] The task process management role is started through the No. 1 role, and the task behavior execution role is started through the task process management role.
[0062] Optionally, initiating the task process management role through the No. 1 role in the task management module includes:
[0063] The first role listens to the task flow startup requirement and calls the fork system call to create an initial child process;
[0064] By calling the execlp system call through the No. 1 role, the created initial child process is replaced with the task role management process;
[0065] The task flow management role is started by using the replaced initial sub-process.
[0066] Optionally, initiating the task process management role through the No. 1 role in the task management module includes:
[0067] Obtain the configuration file of role 1, read the configuration file through role 1, and call the fork system call to create a configuration child process;
[0068] By calling the execlp system call through the No. 1 role, the created configuration sub-process is replaced with the task flow management process;
[0069] The replaced startup sub-process is used to start the task flow management role.
[0070] Optionally, the task management module starts the task behavior execution role through the task process management role, including:
[0071] Based on the task process startup requirement, the role name of the task behavior execution role to be started and the task status of the resource access task are obtained;
[0072] According to the role name of the task behavior execution role to be started and the task status of the resource access task, the StartActor role startup interface is called by the task process management role to start the task behavior execution role corresponding to the role name.
[0073] Optionally, the task management module calls the StartActor role startup interface through the task process management role to start the task behavior execution role corresponding to the role name, including:
[0074] Call the StartActor role startup interface through the task process management role;
[0075] Reading the resource configuration file of the task behavior execution role through the resource role to obtain the requested resources required by the task behavior execution role when executing the resource access task; the resource configuration file includes: role name, requested resources and resource access mode;
[0076] The requested resources are allocated through the resource roles, and according to the result of the resource allocation, the task behavior execution role corresponding to the role name is started.
[0077] Optionally, the task management module allocates the requested resources according to the resource roles, including:
[0078] Obtaining a resource access data table for the resource role; the resource access data table includes: a resource identifier, a resource name, a resource access mode, an access role list, and a health level attribute;
[0079] According to the resource access data table, a resource access mode corresponding to the requested resource is obtained; the resource access mode includes: resource sharing and resource exclusivity;
[0080] When the resource access mode corresponding to the requested resource is resource sharing, the role name of the task behavior execution role is added to the access role list of the resource access data table, and resource allocation is performed on the requested resource;
[0081] When the resource access mode corresponding to the requested resource is resource exclusive, check whether the access role list of the resource access data table is empty. If the access role list is not empty, add the role name of the task behavior execution role to the task role waiting queue; if the access role list is empty, allocate resources to the requested resource.
[0082] Optionally, the task management module starts the task behavior execution role corresponding to the role name according to the result of the resource allocation, including:
[0083] When the resource allocation result shows that the requested resource is successfully allocated, the task flow management role calls a fork system call to create an execution child process;
[0084] Calling the execlp system call through the task flow management role replaces the created execution sub-process with the process of the task behavior execution role;
[0085] The replaced execution sub-process is used to start the task behavior execution role corresponding to the role name.
[0086] Optionally, after starting the task behavior execution role corresponding to the role name, the task management module further includes:
[0087] According to the obtained role name of the task behavior execution role to be stopped, the StopActor role stop interface is called through the task flow management role to stop the task behavior execution role.
[0088] Optionally, the task management module calls a StopActor role stop interface through the task flow management role to stop the task behavior execution role, including:
[0089] Calling the StopActor role stop interface through the task process management role;
[0090] Reading the resource configuration file of the task behavior execution role to be stopped through the resource role to obtain the requested resources of the task behavior execution role to be stopped;
[0091] According to the resource access data table of the resource role, the resource access mode corresponding to the requested resource of the task behavior execution role to be stopped is obtained; when the resource access mode corresponding to the requested resource is resource exclusive, the to-be-released resource associated with the task behavior execution role to be stopped is obtained, and it is checked whether the task role waiting queue contains a task behavior execution role requesting the to-be-released resource; if so, the role name of the task behavior execution role is deleted from the task role waiting queue, and the task behavior execution role is started;
[0092] According to the resource access data table of the resource role, the role name of the task behavior execution role to be stopped is deleted from the access role list of the resource access data table; and a kill system call is called to stop the task behavior execution role.
[0093] Based on the same inventive concept, the present invention also provides a role-based multi-task software system monitoring method, comprising:
[0094] Get the process identifier of role 1 in the multi-tasking software system;
[0095] According to the process identifier of the No. 1 role, monitoring abnormal signals of the No. 1 role, resource roles and task roles in the multi-task software system;
[0096] According to the abnormal signal, obtaining call stack information corresponding to the abnormal signal;
[0097] Performing exception location on the exception signal according to the call stack information to obtain exception location information in the multi-task software system;
[0098] Among them, the multi-task software system is a multi-task software system constructed by the role-based multi-task software system construction method as described above; the role No. 1 is the role No. 1 in the multi-task software system constructed by the role-based multi-task software system construction method as described above; the resource role is a resource role in the multi-task software system constructed by the role-based multi-task software system construction method; the task role is a task role in the multi-task software system constructed by the role-based multi-task software system construction method.
[0099] Optionally, monitoring abnormal signals of role No. 1, resource role, and task role in the multi-task software system according to the process identifier of role No. 1 includes:
[0100] According to the process identifier of the No. 1 role, obtain the process identifier of the descendant process corresponding to the No. 1 role;
[0101] Obtaining, according to the process identifier of the No. 1 role and the process identifiers of the descendant processes corresponding to the No. 1 role, a process structure of the No. 1 role and its descendant processes, and adding the process structure of the No. 1 role and its descendant processes to a monitored role mapping table;
[0102] Track the No. 1 role and start monitoring abnormal signals of the No. 1 role, resource roles and task roles in the multi-task software system.
[0103] Optionally, adding the process structure of the No. 1 role and its descendant processes to the monitored role mapping table includes:
[0104] Using the process ID of the process identifier of role 1 and its descendant processes as the key and the process structure corresponding to the role 1 and its descendant processes as the value, the key and value form a key-value pair and add it to the monitored role mapping table;
[0105] The process structure includes one or more of the following: process name, process ID, parent process ID, parent thread ID, process start and end time, process running status, process exit code, process CPU occupancy, process memory occupancy, process exit stack information and a list of all threads of the process.
[0106] Optionally, tracking the No. 1 role and starting to monitor abnormal signals of the No. 1 role, resource roles, and task roles in the multi-task software system includes:
[0107] By calling the ptrace system call, the process of tracing the role No. 1 and its descendant processes;
[0108] The waitpid system call is called according to a preset time period to obtain abnormal signals of the No. 1 role, the resource role and the task role in the multi-task software system.
[0109] Optionally, obtaining call stack information corresponding to the exception signal according to the exception signal includes:
[0110] Obtaining, according to the abnormal signal, a process identifier of a role in the multi-task software system where the abnormality occurs;
[0111] Obtaining call stack information corresponding to the abnormal signal according to the process identifier of the role where the abnormality occurs;
[0112] The call stack information includes: function name, executable program name, source code file name and source code line number information.
[0113] Optionally, obtaining call stack information corresponding to the abnormal signal according to the process identifier of the role where the abnormality occurs includes:
[0114] Obtaining a function name according to a process identifier of a role in which an exception occurs in the multi-tasking software system;
[0115] Decode the function name to obtain call stack function information corresponding to the function name;
[0116] Obtaining the executable program name corresponding to the function name according to the call stack function information;
[0117] Disassembling the executable program name to obtain a static address corresponding to the function name;
[0118] According to the executable program name and the static address corresponding to the function name, the source code file information and source code line number information corresponding to the function name are obtained.
[0119] Optionally, after performing exception location on the abnormal signal according to the call stack information to obtain exception location information in the multi-task software system, the method further includes:
[0120] generating an exception response strategy based on the exception location information and preset user intervention instructions in the multi-tasking software system;
[0121] According to the abnormal response strategy, emergency processing is performed on the multi-task software system.
[0122] Optionally, performing emergency processing on the multi-task software system according to the abnormal response strategy includes:
[0123] When the abnormal response strategy is to restart the multi-task software system, performing emergency processing on the multi-task software system by restarting the No. 1 role;
[0124] When the abnormal response strategy is to restart the role where the abnormality occurs, emergency processing is performed on the multi-task software system by restarting the role where the abnormality occurs.
[0125] Based on the same inventive concept, the present invention also provides a monitoring system for a role-based multi-task software system, comprising:
[0126] Identifier acquisition module: used to obtain the process identifier of role No. 1 in the multi-tasking software system;
[0127] An abnormal monitoring module: used for monitoring abnormal signals of the No. 1 role, resource roles and task roles in the multi-task software system according to the process identifier of the No. 1 role;
[0128] The information calling module is used to obtain the call stack information corresponding to the abnormal signal according to the abnormal signal; and to locate the abnormality of the abnormal signal according to the call stack information to obtain the abnormality location information in the multi-task software system.
[0129] Optionally, the abnormality monitoring module is specifically used to:
[0130] According to the process identifier of the No. 1 role, obtain the process identifier of the descendant process corresponding to the No. 1 role;
[0131] Obtaining, according to the process identifier of the No. 1 role and the process identifiers of the descendant processes corresponding to the No. 1 role, a process structure of the No. 1 role and its descendant processes, and adding the process structure of the No. 1 role and its descendant processes to a monitored role mapping table;
[0132] Track the No. 1 role and start monitoring abnormal signals of the No. 1 role, resource roles and task roles in the multi-task software system.
[0133] Optionally, the abnormal monitoring module adds the process structure of the No. 1 role and its descendant processes to the monitored role mapping table, including:
[0134] Using the process ID of the process identifier of role 1 and its descendant processes as the key and the process structure corresponding to the role 1 and its descendant processes as the value, the key and value form a key-value pair and add it to the monitored role mapping table;
[0135] The process structure includes one or more of the following: process name, process ID, parent process ID, parent thread ID, process start and end time, process running status, process exit code, process CPU occupancy, process memory occupancy, process exit stack information and a list of all threads of the process.
[0136] Optionally, the abnormal monitoring module tracks the No. 1 role and starts monitoring abnormal signals of the No. 1 role, resource roles, and task roles in the multi-task software system, including:
[0137] By calling the ptrace system call, the process of tracing the role No. 1 and its descendant processes;
[0138] The waitpid system call is called according to a preset time period to obtain abnormal signals of the No. 1 role, the resource role and the task role in the multi-task software system.
[0139] Optionally, the information calling module obtains call stack information corresponding to the abnormal signal according to the abnormal signal, including:
[0140] Obtaining, according to the abnormal signal, a process identifier of a role in the multi-task software system where the abnormality occurs;
[0141] Obtaining call stack information corresponding to the abnormal signal according to the process identifier of the role where the abnormality occurs;
[0142] The call stack information includes: function name, executable program name, source code file name and source code line number information.
[0143] Optionally, the information calling module obtains call stack information corresponding to the abnormal signal according to the process identifier of the role where the abnormality occurs, including:
[0144] Obtaining a function name according to a process identifier of a role in which an exception occurs in the multi-tasking software system;
[0145] Decode the function name to obtain call stack function information corresponding to the function name;
[0146] Obtaining the executable program name corresponding to the function name according to the call stack function information;
[0147] Disassembling the executable program name to obtain a static address corresponding to the function name;
[0148] According to the executable program name and the static address corresponding to the function name, the source code file information and source code line number information corresponding to the function name are obtained.
[0149] Optionally, after performing exception location on the abnormal signal according to the call stack information to obtain exception location information in the multi-task software system, the information calling module further includes:
[0150] generating an exception response strategy based on the exception location information and preset user intervention instructions in the multi-tasking software system;
[0151] According to the abnormal response strategy, emergency processing is performed on the multi-task software system.
[0152] Optionally, the information calling module performs emergency processing on the multi-task software system according to the abnormal response strategy, including:
[0153] When the abnormal response strategy is to restart the multi-task software system, performing emergency processing on the multi-task software system by restarting the No. 1 role;
[0154] When the abnormal response strategy is to restart the role where the abnormality occurs, emergency processing is performed on the multi-task software system by restarting the role where the abnormality occurs.
[0155] In yet another aspect, the present invention further provides a computer device comprising: one or more processors;
[0156] a memory for storing one or more programs;
[0157] When the one or more programs are executed by the one or more processors, the aforementioned method for constructing a role-based multi-task software system or a method for monitoring a role-based multi-task software system is implemented.
[0158] On the other hand, the present invention also provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed, it implements a method for constructing a role-based multi-task software system or a method for monitoring a role-based multi-task software system as described above.
[0159] Compared with the prior art, the present invention has the following beneficial effects:
[0160] 1. The present invention provides a method and system for constructing a role-based multi-task software system, comprising: starting role No. 1 based on a multi-task software system startup instruction; starting a resource role through the role No. 1, wherein the resource role is used to provide resource services for the task role; obtaining a resource access task based on an acquired task flow startup requirement, starting a task role through the role No. 1, wherein the task role is used to execute the resource access task; taking the role No. 1 as a root node and the resource role and the task role as descendant nodes to construct a role tree, thereby obtaining a role-based multi-task software system; when constructing the multi-task software system, the present application starts role No. 1, and starts resource roles and task roles through role No. 1, thereby clarifying the calling relationship within the system; taking role No. 1 as the root node of the multi-task software system and the resource role and task role as descendant nodes of the multi-task software system, thereby clarifying the structural relationship within the multi-task software system, so that the multi-task software system constructed by the present invention can clarify the internal structure and calling relationship of the system and monitor the status changes of subtasks in real time.
[0161] 2. The present invention provides a role-based monitoring method and system for a multi-tasking software system, comprising: obtaining a process identifier of role No. 1 in the multi-tasking software system; monitoring abnormal signals of role No. 1, resource roles, and task roles in the multi-tasking software system based on the process identifier of role No. 1; obtaining call stack information corresponding to the abnormal signal based on the abnormal signal; locating the abnormal signal based on the call stack information to obtain abnormal location information in the multi-tasking software system; the present application can monitor the global operating status of the multi-tasking software system by tracking role No. 1, without having to check the operating status of each role one by one, which is beneficial to improving the efficiency of software system abnormality monitoring. BRIEF DESCRIPTION OF THE DRAWINGS
[0162] Figure 1 A flowchart of a method for constructing a role-based multi-task software system provided by the present invention;
[0163] Figure 2 An architectural diagram of a role-based multi-task software system provided by the present invention;
[0164] Figure 3 A schematic diagram of the structure of a construction system for a role-based multi-task software system provided by the present invention;
[0165] Figure 4 A flowchart of a role-based multi-task software system monitoring method provided by the present invention;
[0166] Figure 5 A schematic diagram of a monitoring architecture in a role-based multi-task software system monitoring method provided by the present invention;
[0167] Figure 6 An example diagram of a role tree for a role-based multi-tasking software system provided by the present invention;
[0168] Figure 7 An example diagram of role tree monitoring displayed on the monitoring front end in a monitoring method for a role-based multi-task software system provided by the present invention;
[0169] Figure 8 An example diagram of monitoring detailed information of roles displayed on a monitoring front end in a monitoring method of a role-based multi-task software system provided by the present invention;
[0170] Figure 9 A schematic diagram of overall monitoring interaction in a role-based multi-task software system monitoring method provided by the present invention;
[0171] Figure 10 A schematic diagram of the structure of a monitoring system for a role-based multi-tasking software system provided by the present invention;
[0172] Figure 11 This is a structural diagram of an electronic device provided by the present invention. DETAILED DESCRIPTION
[0173] The present invention proposes a method and system for constructing and monitoring a role-based multi-task software system. The specific embodiments of the present invention are further described in detail below with reference to the accompanying drawings.
[0174] Example 1:
[0175] A method for constructing a role-based multi-task software system, the flow chart is as follows Figure 1 Shown, including:
[0176] Step 1: Based on the multi-tasking software system startup instruction, start role 1;
[0177] Step 2: Start the resource role through role 1. The resource role is used to provide resource services for the task role.
[0178] Step 3: Based on the obtained task process startup requirements, obtain the resource access task and start the task role through role 1. The task role is used to execute the resource access task.
[0179] Step 4: Take role No. 1 as the root node, and the resource role and task role as descendant nodes to construct a role tree and obtain a role-based multi-task software system.
[0180] In general, existing multi-task software systems, especially robotic multi-task software systems, create multiple processes in a multi-core CPU (Central Processing Unit) environment. Each process can run independently on a different CPU core to fully utilize hardware resources and relatively isolate the processes. However, communication overhead is high. Due to the unclear internal structure and call relationships of the system, it becomes difficult to grasp the status of all subtasks in real time and determine whether the system is operating normally. Some dynamically created subtasks may terminate abnormally without being detected. In addition, the number of software developers involved is large, and when an abnormality occurs, a lot of manpower and time are required to check each software module one by one, making it difficult to quickly locate the cause of the problem. To address the management and monitoring difficulties faced by the above-mentioned multi-task software system, the present invention constructs a role-based multi-task software system by taking role 1 as the root node and resource roles and task roles as descendant nodes. Wherein, "role" refers to the basic scheduling unit for task execution in the multi-task software system. Specifically, the multi-task software system is a specific task process running on an individual platform. The multi-task software system constructed based on roles facilitates task-oriented resource management and can facilitate emergency handling such as rapid fault location and abnormal recovery during system operation.
[0181] Specifically, such as Figure 2As shown, the multi-task software system constructed by the construction method in this embodiment is constructed by three types of roles: role 1, resource role, and task role. Among them, role 1 and resource role are static roles, created when the system starts, and task role is a dynamic role, dynamically created according to the task process startup requirements. Role 1 is the startup entry of the multi-task software system, responsible for starting and managing other roles of the multi-task software system. When role 1 stops, all roles of the multi-task software system exit; resource role is mainly responsible for resource management, such as resource roles that can manage sensors, controllers, multi-network devices, multi-network protocols, intelligent models, intelligent accelerators, etc. This helps to optimize resource allocation, manage resource conflicts, improve resource utilization, and thus improve the performance of the entire system. Resource role provides a resource management interface for task role, arbitrates and allocates resources, and provides resource services for task role; task role is divided into two levels, namely task process management role and task behavior execution role. This hierarchical task management helps to clearly define and control the order and conditions of task execution, avoids complex logical confusion, and improves the accuracy and efficiency of execution. In summary, the multi-task software system architecture in this embodiment not only improves the system's fault location efficiency and resource management capabilities, but also enhances the system's flexibility and scalability. It is an effective strategy in the design of modern complex software systems. In addition, the multi-task software system of the present invention can also be connected to hardware devices and monitoring processes respectively. The connection with the hardware device can be used to directly or indirectly control and manage the underlying hardware resources; the connection with the monitoring process can be used to improve the efficiency of software system abnormality monitoring.
[0182] In one implementation, the process of starting the resource role through role 1 in step 2 may include:
[0183] Call the fork system call through role 1 to create and start the child process;
[0184] Call the execlp system call through role 1 to replace the created startup child process with the resource role process;
[0185] Use the replaced startup sub-process to start the resource role;
[0186] In this implementation, role No. 1 creates a child process by calling the fork system call, and replaces the created child process with the resource role process by calling the execlp system call; and when role No. 1 exits, the kill system call is called to close all resource role child processes; wherein, the fork system call is a method for creating a new process in Unix and Unix-like operating systems (such as Linux); the execlp system call is a method for executing a new program and replacing the current process in Unix and Unix-like systems (such as Linux); the kill system call is a method for sending a signal to a running process (such as a signal to stop working, pause, continue, or perform some cleanup actions) in Unix and Unix-like systems (such as Linux).
[0187] In one implementation, the above-mentioned task roles can be divided into task process management roles and task behavior execution roles;
[0188] Among them, the task process management role can be used to manage the task behavior execution role;
[0189] The task behavior execution role can be used to perform resource access tasks;
[0190] In this implementation, the process of starting the task role through role 1 may include:
[0191] Start the task process management role through role No. 1, and start the task behavior execution role through the task process management role.
[0192] In this implementation, the process of starting the task flow management role through role 1 may include:
[0193] The task process starts by monitoring the demand through role 1, and calls the fork system call to create the initial child process;
[0194] By calling the execlp system call through role 1, the initial child process created is replaced with the task role management process;
[0195] Use the replaced initial sub-process to start the task process management role.
[0196] In this implementation, the above-mentioned initiation of the task process management role through role 1 includes:
[0197] Get the configuration file of role 1, read the configuration file through role 1, and call the fork system call to create a configuration child process;
[0198] Call the execlp system call through role 1 to replace the created configuration subprocess with the task flow management process;
[0199] The replaced startup subprocess is used to start the task flow management role; the execlp system call allows role No. 1 to load and execute a new program in the subprocess, namely the task flow management role process. This enables the system to dynamically load and run different task management logics as needed, which is conducive to increasing the flexibility and scalability of the system.
[0200] In this implementation, the present invention provides a two-level task role start / stop method: (1) starting and stopping the task process management role; and (2) starting and stopping the task behavior execution role. By independently controlling the start and stop of these two types of task roles, resource usage can be more precisely managed. Resources are dynamically requested and released on a role-by-role basis, with resource arbitration and allocation performed when a task role is started and resource release performed when the task role is stopped, thus achieving resource conflict management.
[0201] For example, the process of starting and stopping the task process management role may be: reading a configuration file through role 1 or monitoring a remote task process startup request, wherein the configuration file is configured with the name of the task process management role to be started by the multi-task software system;
[0202] Role 1 calls the fork system call to create a child process, and calls the execlp system call to replace the created child process with the task flow management role process;
[0203] When role 1 exits, it calls the kill system call to close all task flow management role subprocesses.
[0204] The process of starting and stopping the task behavior execution role can be as follows: the role-based resource management module provides a resource management interface (API) for the task process management role to start and stop the task behavior execution role.
[0205] In one implementation, the process of initiating the task behavior execution role through the task process management role may include:
[0206] Based on the task process startup requirements, obtain the role name of the task behavior execution role to be started and the task status of the resource access task;
[0207] According to the role name of the task behavior execution role to be started and the task status of the resource access task, the StartActor role startup interface is called through the task process management role to start the task behavior execution role corresponding to the role name; wherein, the calling function corresponding to the StartActor role startup interface can be expressed as:
[0208] StartActor(string actor_name,string task_status);
[0209] Among them, string represents the string type; actor_name represents the role name; task_status represents the task status; the task process management role starts the interface by calling the StartActor role, and the input parameters are the "role name of the task behavior execution role" to be started and the "task status"; the "task status" parameter describes the startup status of the task. When an exception occurs in the behavior execution role and emergency processing is required, execution can be resumed according to this task status.
[0210] In this implementation, the process of calling the StartActor role startup interface through the task flow management role to start the task behavior execution role corresponding to the role name may include:
[0211] Call the StartActor role startup interface through the task process management role;
[0212] Read the resource configuration file of the task behavior execution role through the resource role to obtain the requested resources required by the task behavior execution role when performing the resource access task; the resource configuration file may include: role name, requested resources and resource access mode;
[0213] Resource roles are used to allocate requested resources, and based on the resource allocation results, the task behavior execution role corresponding to the role name is started.
[0214] In this implementation, the process of allocating requested resources based on resource roles may include:
[0215] Obtain a resource access data table for a resource role; for example, the resource access data table may include: a resource identifier, a resource name, a resource access mode, an access role list, and a health level attribute;
[0216] Obtaining a resource access mode corresponding to the requested resource according to the resource access data table; for example, the resource access mode may include: resource sharing and resource exclusivity;
[0217] When the resource access mode corresponding to the requested resource is resource sharing, the role name of the task behavior execution role is added to the access role list of the resource access data table, and resource allocation is performed on the requested resource;
[0218] When the resource access mode corresponding to the requested resource is resource exclusive, check whether the access role list of the resource access data table is empty. If the access role list is not empty, add the role name of the task behavior execution role to the task role waiting queue; if the access role list is empty, allocate resources to the requested resource; in this implementation method, the present invention provides a resource management interface for the task process management role through the resource role, performs task-oriented resource management, arbitrates and allocates resources for the task behavior execution role according to different access modes of resources, and provides a solution to resource conflicts in the dynamic task execution process. By providing a two-level start and stop mode of the task process management role and the task behavior execution role, resources are dynamically applied for and released on a role basis, resource arbitration and allocation are performed when the task role is started, and resource release is performed when the task role is stopped, thereby completing resource conflict management.
[0219] In this implementation, the process of starting the task behavior execution role corresponding to the role name according to the resource allocation result may include:
[0220] When the resource allocation result shows that the requested resources are successfully allocated, the task flow management role calls the fork system call to create an execution child process;
[0221] Call the execlp system call through the task process management role to replace the created execution sub-process with the process of the task behavior execution role;
[0222] Use the replaced execution sub-process to start the task behavior execution role corresponding to the role name.
[0223] After the task behavior execution role corresponding to the above startup role name, it can also include:
[0224] According to the role name of the task behavior execution role to be stopped, the task process management role calls the StopActor role stop interface to stop the task behavior execution role;
[0225] For example, the calling function corresponding to the StopActor role stop interface can be expressed as:
[0226] StopActor(string actor_name);
[0227] string indicates a string type; actor_name indicates the role name; the task process management role calls the StopActor role stop interface, and the input parameter is the "role name of the task behavior execution role" to be stopped;
[0228] The above process of calling the StopActor role stop interface through the task process management role to stop the task behavior execution role may include:
[0229] Call the StopActor role stop interface through the task process management role;
[0230] Read the resource configuration file of the task behavior execution role to be stopped through the resource role to obtain the requested resources of the task behavior execution role to be stopped;
[0231] According to the resource access data table of the resource role, the resource access mode corresponding to the requested resource of the task behavior execution role to be stopped is obtained; when the resource access mode corresponding to the requested resource is resource exclusive, the to-be-released resources associated with the task behavior execution role to be stopped are obtained, and it is checked whether the task role waiting queue contains the to-be-released resources requested by the task behavior execution role; if so, the role name of the task behavior execution role is deleted from the task role waiting queue, and the task behavior execution role is started;
[0232] According to the resource access data table of the resource role, delete the role name of the task behavior execution role to be stopped from the access role list of the resource access data table; and call the kill system call to stop the task behavior execution role;
[0233] In this implementation, the role-based resource management module of the present invention provides resource management interfaces (e.g., StartActor and StopActor interfaces) for the task flow management role to start and stop the task behavior execution role. When the task flow management role is started, it arbitrates and allocates resources for the task behavior execution role based on different resource access modes; when the role is stopped, it releases resources. The specific process may include the following:
[0234] 1) Resource access data table
[0235] Each resource role maintains a "resource access data table" that records the access relationship between resources and roles. The resource access data table can contain resource ID, resource name, access mode, access role list and health level attributes, as shown in Table 1:
[0236] Table 1 Resource access data table
[0237] Resource ID Resource Name Access Mode Access Role List Health Level dev0 sensor1 shared actor1 / actor2 / actor3 10 dev1 controller2 exclusive actor1 10
[0238] Shared access mode allows multiple roles to use the resource at the same time. For example, the resource ID of the sensor named sensor1 is dev0, and its access mode is shared access. It is being used by actor1, actor2, and actor3, and the health level of the resource dev0 is 10.
[0239] Exclusive access mode allows only one role to use the resource at the same stage. For example, the access mode of the requested resource ID: dev1 corresponding to the controller named controller2 is exclusive access and is being used by the role actor1. The health level of the resource dev1 is 10.
[0240] 2) Task role resource configuration file
[0241] The task role resource profile describes the resources and access modes required by the behavior execution role, as shown in Table 2:
[0242] Table 2 Task role resource configuration file
[0243] Character Name Requesting Resources Access Mode actor1 sensor1 / controller2 Shared / Exclusive actor2 sensor1 shared actor3 sensor1 shared
[0244] 3) Resource arbitration and resource release process
[0245] For example, the task role initiation and resource arbitration process is as follows:
[0246] (1) The task process management role calls the StartActor role startup interface and passes in the role name and task status of the task behavior execution role to be started.
[0247] (2) The resource management module reads the “request resource” corresponding to the task behavior execution role in the task role resource configuration file.
[0248] (3) The resource management module obtains the “resource access data table” of each resource role and checks the resource access mode corresponding to the “request resource”.
[0249] If the access mode is "shared", add the name of the action role to the "access role list" corresponding to the "resource access data table", and go to step (4) to start the task role;
[0250] If the access mode is "exclusive", check whether the "Access Role List" corresponding to the "Resource Access Data Table" is empty. If it is empty, it means that the resource is not used by other roles, and go to step (4) to start the task role; if it is not empty, it means that the resource is occupied by other roles, and the task role does not meet the startup conditions yet, so it is added to the task role waiting queue.
[0251] (4) When the task role is started, the fork system call is called to create a child process, and the execlp system call is called to replace the child process with the task role process that should be started in step (3).
[0252] For example, the process of stopping a task role and releasing resources is as follows:
[0253] (1) The task process management role calls the StopActor role stop interface and passes in the role name of the task behavior execution role to be stopped.
[0254] (2) The resource management module reads the “request resource” corresponding to the task behavior execution role in the task role resource configuration file.
[0255] (3) The resource management module obtains the "resource access data table" of each resource role, deletes the task role name in the "access role list" corresponding to the "resource access data table", and calls the kill system call to stop the task role process.
[0256] (4) Check the access mode of the resource in the "Resource Access Data Table".
[0257] If the access mode is "exclusive", check the "task role waiting" queue. If there is a task role in the "task role waiting" queue requesting the same resource, remove this task role from the task queue and re-execute the resource arbitration process of the task role. The above technical solution can prevent resource conflicts. When multiple task roles request the same exclusive resource, the resource conflict can be resolved by monitoring the "task role waiting" queue.
[0258] The present invention aims to solve the problem that the structure and call relationship of the existing multi-task software system are unclear, resulting in the inability to grasp the status of all subtasks in real time. The present invention proposes a method for constructing a multi-task software system based on roles. The method takes role 1 as the root node, resource roles and task roles as descendant nodes, and constructs the multi-task software system through three types of roles. Based on the multi-task software system startup instruction, role 1 is started, and the resource role and the task role corresponding to the task process startup requirement are started by role 1, thereby clarifying the internal structure and call relationship of the system. In addition, the present invention also provides a two-level start-stop method for the task process management role and the task behavior execution role, dynamically applies for and releases resources based on the role, performs resource arbitration and allocation when the task role is started, and releases resources when the task role is stopped, completing resource conflict management, so that the present invention can perform task-oriented resource management and realize a solution to resource conflicts in dynamic task execution. In summary, the multi-task software system constructed by the method of the present invention, by clarifying the internal structure and call relationship of the system based on roles, is conducive to real-time monitoring of the status changes of subtasks, thereby improving the overall visibility and transparency of the system. When a system failure occurs, the role-based structure helps to quickly locate the role and subtask where the problem occurs, reducing the fault diagnosis time.
[0259] Example 2:
[0260] The present invention based on the same inventive concept also provides a system for constructing a multi-task software system based on a role, the structural composition diagram of which is shown in FIG. Figure 3 As shown, including:
[0261] Task startup module: used to start role 1 based on the multi-task software system startup instruction;
[0262] Resource management module: used to start resource roles through role 1. Resource roles are used to provide resource services for task roles.
[0263] Task management module: used to obtain resource access tasks based on the acquired task process startup requirements, start the task role through role No. 1, and the task role is used to execute the resource access task; take role No. 1 as the root node and the task role as the descendant node to build a role tree and obtain a role-based multi-task software system.
[0264] In a possible implementation, the process of starting a resource role through role 1 in the resource management module may include:
[0265] Call the fork system call through role 1 to create and start the child process;
[0266] Call the execlp system call through role 1 to replace the created startup child process with the resource role process;
[0267] The resource role is started by using the replaced startup child process; wherein, the fork system call is a method for creating a new process in Unix and Unix-like operating systems (such as Linux); the execlp system call is a method for executing a new program and replacing the current process in Unix and Unix-like systems (such as Linux).
[0268] In a possible implementation, the task roles in the task management module may include a task process management role and a task behavior execution role;
[0269] Among them, the task process management role is used to manage the task behavior execution role;
[0270] The task behavior execution role is used to perform resource access tasks;
[0271] In a possible implementation, the process of starting the task role through role 1 may include:
[0272] Start the task process management role through role No. 1, and start the task behavior execution role through the task process management role.
[0273] In a possible implementation, the process of starting the task flow management role through role 1 in the task management module may include:
[0274] The task process starts by monitoring the demand through role 1, and calls the fork system call to create the initial child process;
[0275] By calling the execlp system call through role 1, the initial child process created is replaced with the task role management process;
[0276] Use the replaced initial sub-process to start the task process management role.
[0277] In a possible implementation, the process of starting the task flow management role through role 1 in the task management module may include:
[0278] Get the configuration file of role 1, read the configuration file through role 1, and call the fork system call to create a configuration child process;
[0279] Call the execlp system call through role 1 to replace the created configuration subprocess with the task flow management process;
[0280] Use the replaced startup sub-process to start the task process management role.
[0281] In a possible implementation, the process of initiating the task behavior execution role through the task flow management role in the task management module may include:
[0282] Based on the task process startup requirements, obtain the role name of the task behavior execution role to be started and the task status of the resource access task;
[0283] According to the role name of the task behavior execution role to be started and the task status of the resource access task, the StartActor role startup interface is called through the task process management role to start the task behavior execution role corresponding to the role name.
[0284] In a possible implementation, in the task management module, the process of calling the StartActor role startup interface through the task process management role to start the task behavior execution role corresponding to the role name may include:
[0285] Call the StartActor role startup interface through the task process management role;
[0286] Read the resource configuration file of the task behavior execution role through the resource role to obtain the requested resources required by the task behavior execution role when executing the resource access task; the resource configuration file includes: role name, requested resources and resource access mode;
[0287] Resource roles are used to allocate requested resources, and based on the resource allocation results, the task behavior execution role corresponding to the role name is started.
[0288] In a possible implementation, the process of allocating requested resources based on resource roles in the task management module may include:
[0289] Obtain resource access data table of resource roles; resource access data table includes: resource identifier, resource name, resource access mode, access role list and health level attribute;
[0290] According to the resource access data table, the resource access mode corresponding to the requested resource is obtained; the resource access mode includes: resource sharing and resource exclusive;
[0291] When the resource access mode corresponding to the requested resource is resource sharing, the role name of the task behavior execution role is added to the access role list of the resource access data table, and resource allocation is performed on the requested resource;
[0292] When the resource access mode corresponding to the requested resource is resource exclusive, check whether the access role list in the resource access data table is empty. If the access role list is not empty, add the role name of the task behavior execution role to the task role waiting queue; if the access role list is empty, allocate resources to the requested resource.
[0293] In a possible implementation, the process of starting the task behavior execution role corresponding to the role name in the task management module according to the resource allocation result may include:
[0294] When the resource allocation result shows that the requested resources are successfully allocated, the task flow management role calls the fork system call to create an execution child process;
[0295] Call the execlp system call through the task process management role to replace the created execution sub-process with the process of the task behavior execution role;
[0296] Use the replaced execution sub-process to start the task behavior execution role corresponding to the role name.
[0297] In a possible implementation, after starting the task behavior execution role corresponding to the role name, the task management module may further include:
[0298] According to the role name of the task behavior execution role to be stopped, the task process management role calls the StopActor role stop interface to stop the task behavior execution role.
[0299] In a possible implementation, in the task management module, the task flow management role calls the StopActor role stop interface, and the process of stopping the task behavior execution role may include:
[0300] Call the StopActor role stop interface through the task process management role;
[0301] Read the resource configuration file of the task behavior execution role to be stopped through the resource role to obtain the requested resources of the task behavior execution role to be stopped;
[0302] According to the resource access data table of the resource role, the resource access mode corresponding to the requested resource of the task behavior execution role to be stopped is obtained; when the resource access mode corresponding to the requested resource is resource exclusive, the to-be-released resources associated with the task behavior execution role to be stopped are obtained, and it is checked whether the task role waiting queue contains the to-be-released resources requested by the task behavior execution role; if so, the role name of the task behavior execution role is deleted from the task role waiting queue, and the task behavior execution role is started;
[0303] According to the resource access data table of the resource role, the role name of the task behavior execution role to be stopped is deleted from the access role list of the resource access data table; and the kill system call is called to stop the task behavior execution role.
[0304] Example 3:
[0305] The present invention based on the same inventive concept also provides a monitoring method for a multi-task software system based on a role, the flow chart of which is shown in FIG. Figure 4 As shown, including:
[0306] Step S1: Obtain the process identifier of role No. 1 in the multi-tasking software system;
[0307] Step S2: monitoring abnormal signals of role No. 1, resource role, and task role in the multi-task software system according to the process identifier of role No. 1;
[0308] Step S3: obtaining call stack information corresponding to the abnormal signal according to the abnormal signal; and locating the abnormal signal according to the call stack information to obtain abnormal location information in the multi-tasking software system;
[0309] Among them, the multi-task software system is a multi-task software system constructed by the previous role-based multi-task software system construction method; role No. 1 is role No. 1 in the multi-task software system constructed by the previous role-based multi-task software system construction method; the resource role is a resource role in the multi-task software system constructed by the role-based multi-task software system construction method; and the task role is a task role in the multi-task software system constructed by the role-based multi-task software system construction method.
[0310] When monitoring a multi-task software system, first start the monitoring process running on the distributed task platform as the monitoring subject, and then start role 1; after role 1 is started, send the process identifier of role 1 to the monitoring process (for example, the process identifier of role 1 is represented by pid), and finally select the object to be monitored through the monitoring front-end interface and display the monitoring results. For example, Figure 5 As shown, in the monitoring front-end interface, the task platform to be monitored (for example, task platform 1, task platform 2, ..., task platform n, where n represents the total number of task platforms) is selected as the object to be monitored for monitoring connection, and monitoring data from the monitoring process on the task platform side is received in real time (the monitoring data can be, for example, abnormal signals corresponding to role No. 1, resource role, task flow management role or task behavior execution role) and constructed, displayed, warned and controlled; the present invention uses role No. 1 as the startup entry of the multi-task software system to construct a multi-task software system role tree with role No. 1 as the root node and other resource roles and task roles as descendant nodes of role No. 1. In the process of monitoring the multi-task software system, it is only necessary to track and listen to role No. 1 to monitor the running status of each role.
[0311] In one implementation, the process of monitoring abnormal signals of role No. 1, resource role, and task role in the multi-task software system according to the process identifier of role No. 1 in step S2 may include:
[0312] According to the process identifier of role No. 1, get the process identifier of the descendant process corresponding to role No. 1;
[0313] According to the process identifier of role 1 and the process identifier of the descendant process corresponding to role 1, the process structure of role 1 and its descendant process is obtained, and the process structure of role 1 and its descendant process is added to the monitored role mapping table;
[0314] Track role 1 and start monitoring abnormal signals from role 1, resource roles, and task roles in the multi-task software system;
[0315] In this implementation, the process of adding the process structures of role 1 and its descendant processes to the monitored role mapping table may include:
[0316] Using the process number of the process identifier of role 1 and its descendant processes as the key, and the process structure corresponding to role 1 and its descendant processes as the value, the key and value are combined into a key-value pair and added to the monitored role mapping table; in this implementation, the tracking process is added to the "monitored role mapping table" according to the pid number of role 1, wherein the monitored role mapping table uses the process number as the key and the process structure as the value. For example, the process structure may include one or more of the following: process name, process id, parent process id, parent thread id, process start and end time, process running status, process exit code, process CPU occupancy, process memory occupancy, process exit stack information and a list of all threads of the process. For example, taking the process structures named ProcInfo and ThreadInfo as examples, the specific information contained can be expressed as follows:
[0317]
[0318]
[0319] Among them, struct represents a structure; pid_t represents an integer type; string represents a string type; float represents a floating-point data type; int represents a 32-bit integer type; std::map<pid_t,ThreadInfo> threads represents the associative container std::map whose key type is pid_t and value type is ThreadInfo, which is used to store information about all threads associated with the current process;
[0320] In this implementation, the process of tracking role 1 and starting to monitor abnormal signals of role 1, resource roles, and task roles in the multi-task software system may include:
[0321] By calling the ptrace system call, trace the No. 1 role and its descendant processes;
[0322] The waitpid system call is called according to a preset time period to obtain abnormal signals of role 1, resource role, and task role in the multi-tasking software system; wherein, the ptrace system call is a calling method for debugging and monitoring processes in Unix and Unix-like systems (including Linux); the waitpid system call is a system call in Unix and Unix-like systems (including Linux) used to wait for the termination or suspension status of a child process. When the child process terminates or pauses, waitpid returns the pid number of the child process and provides information about the child process status; specifically, the implementation method calls the ptrace system call by the monitoring process, tracks role 1 and starts listening for abnormal signals of other roles. The specific steps are as follows:
[0323] ① Call the ptrace system call to attach the monitoring process to role 1. The ptrace system call expression in this step can be expressed as: ptrace(PTRACE_ATTACH,pid,null,null);
[0324] Among them, pid is the process identifier of role 1; PTRACE_ATTACH is a type of ptrace request, which is used to attach the monitoring process to role 1; null means empty;
[0325] ②Call the ptrace system call and set the option to automatically track the child process of role 1. The ptrace system call expression in this step can be expressed as:
[0326] ptrace(PTRACE_SETOPTIONS,pid,null,PTRACE_O_TRACEFORK|PTRACE_O_TRACECLONE);
[0327] Among them, pid represents the process identifier of role 1; PTRACE_SETOPTIONS is a type of ptrace request, which is used to trace the child process of role 1; null as the third parameter means that no specific address is specified, because PTRACE_SETOPTIONS does not require an address parameter; PTRACE_O_TRACEFORK and PTRACE_O_TRACECLONE are ptrace tracing options, among which PTRACE_O_TRACEFORK is used to: when role 1 calls the fork system call to create a child process, the ptrace system call will automatically start tracing the newly created child process; PTRACE_O_TRACECLONE is similar to PTRACE_O_TRACEFORK, but is aimed at the clone system call. The clone system call allows the creation of a child process that shares certain resources with the parent process; setting the PTRACE_O_TRACECLONE option means that ptrace will also start tracing the child process created by the clone system call. The present invention uses PTRACE_O_TRACEFORK and PTRACE_O_TRACECLONE in combination to ensure that ptrace automatically traces all child processes created by role 1 through a fork system call or a clone system call, which is very useful for debugging complex multi-process applications. In addition, the PTRACE_O_TRACEFORK and PTRACE_O_TRACECLONE options only need to be set for role 1. The newly created child processes (threads) will inherit the options after automatic tracing, and there is no need to set the options for other task roles.
[0328] ③ Periodically call the waitpid system call to wait for abnormal signals from role 1 and the child process. The waitpid system call expression in this step can be expressed as:
[0329] waitpid(pid,&status,WNOHANG);
[0330] Among them, pid represents the process identifier of role 1, with an initial value of -1. If an abnormal signal is received, pid is updated to the pid number of the abnormal process (thread); waitpid is a system call in Unix / Linux systems that is used to wait for the termination or suspension status of a child process. When the child process is terminated or suspended, waitpid returns the pid number of the child process and provides information about the child process status; &status is a pointer to the status variable, which is an integer variable. Waitpid stores the status information of the child process in this variable. For example, the status information may include whether the child process terminated normally, whether it terminated due to receiving a signal, whether it was suspended or continued, etc.; WNOHANG is a flag that, when used with waitpid, instructs waitpid not to block. If no child process has terminated or stopped, waitpid will immediately return a special value (usually 0) instead of blocking as by default, waiting for the child process status to change. This allows the caller to periodically check the child process status without blocking the execution of the main thread. In summary, the waitpid(pid,&status,WNOHANG) call checks without blocking whether any child process (specified or arbitrary) has terminated or hung, and stores the status information in the status variable if available. This approach is very suitable for scenarios where you need to periodically check the status of child processes, such as process monitoring or debugging.
[0331] The ptrace system call used in the present invention is a system call used by the operating system for process tracking. It allows the parent process to control the operation of the child process and can check and change the process space of the child process. When the monitoring process monitors the multi-tasking software system, it is still necessary to set the system administrator (root) authority and process tracking authority for the monitoring process. The Linux system's capability mechanism can be used to set permissions for the monitoring process. The example is as follows (assuming the monitoring process is monitor_node):
[0332] sudo setcap cap_net_raw,cap_net_admin,cap_sys_ptrace=eip / xxx / xxx / monitor_node;
[0333] Among them, the sudo command allows users to run programs with root (system administrator) permissions; setcap is a command-line tool used to modify the Capabilities (permissions) of executable files; Capabilities is a fine-grained permission control mechanism provided by the Linux kernel for processes, allowing processes to have finer-grained permissions than the traditional UNIX permission model without requiring full root permissions; cap_net_raw, cap_net_admin, and cap_sys_ptrace are the names of Capabilities, representing different permissions: cap_net_raw: allows the process to receive raw network data packets, usually used in network monitoring and analysis tools; cap_net_admin: allows the process to configure network interfaces and routing tables, usually used in network management tools; cap_sys_ptrace: allows the process to use the ptrace system call to monitor and control other processes. eip is a permission mask in the Capabilities field, used to control the permissions a process has during execution. / xxx / xxx / monitor_node represents the full path to the monitoring process monitor_node. In summary, this command means running the setcap command with root privileges to grant the three Capabilities permissions (cap_net_raw, cap_net_admin, and cap_sys_ptrace) to the monitoring process / xxx / xxx / monitor_node, and ensuring that these permissions take effect during process execution. This allows the monitoring process to perform network monitoring, network configuration, and process tracking while minimizing the impact on other parts of the system and improving security.
[0334] In this implementation, the generation process of the monitored role mapping table may include:
[0335] (1) The monitoring process uses the netlink protocol to create a netlink socket to listen for system thread creation events (proc_event::PROC_EVENT_FORK) and thread exit events (proc_event::PROC_EVENT_EXIT);
[0336] Among them, netlink is a mechanism for communication between the kernel and user space. It supports active communication initiated by the kernel state. The user state receives the data sent by the kernel based on the socket API and saves it in the netlink socket cache of the receiving process. It is processed by the receiving process and is mainly used for communication between user space programs and kernel space, as well as communication between different subsystems within the kernel. The netlink protocol defines a framework for transmitting information between user space and kernel space. It uses sockets as the communication interface, so you can create a netlink. socket listening system; proc_event can be regarded as an abstract layer here to help us understand different types of kernel events; PROC_EVENT_FORK represents an event type, which indicates that a process or thread has created a new child process or thread through the fork system call. When PROC_EVENT_FORK occurs, the kernel will generate an event notification, which usually contains the process pid, parent process id and other relevant information of the newly created process; PROC_EVENT_EXIT also represents an event type, which indicates that a process or thread has exited or terminated. When a process or thread completes its work, encounters an error, or receives a termination signal, it will exit. When exiting, the kernel will generate a PROC_EVENT_EXIT event, which contains the pid of the exiting process, the exit status code and other information. The monitoring process can track the life cycle of the process by listening to such events, for example, to determine which processes are running, which have terminated, and how they terminated.
[0337] (2) Obtain the thread ID, thread group ID, parent thread ID, and parent thread group ID of the thread in the thread creation event. If at least one of the thread group ID, parent thread ID, and parent thread group ID already exists in the key of the "monitored role mapping table", it means that the newly created thread is part of a multi-tasking software system. Build the role tree according to the following method and add the new process (thread) to the "monitored role mapping table":
[0338] If the thread ID of the newly created thread is the same as the thread group ID, it means that the newly created thread is a process. The new process is added to the "monitored role mapping table" and the process creation time is updated;
[0339] If the thread ID of the newly created thread is different from the thread group ID, it means that the newly created thread is a thread. The thread group ID of the new thread is used as the key value to find the corresponding process from the "monitored role mapping table", add the new thread to the thread list of the process, and update the thread creation time.
[0340] According to the real-time maintained "Monitored Role Mapping Table", each process (except Role 1) can find its parent process information in the "Monitored Role Mapping Table", thereby obtaining a role tree with Role 1 as the root node and resource roles and task roles as its descendant nodes, as shown below: Figure 6 The multi-tasking software system based on the role tree is shown.
[0341] (3) Obtain the thread ID, thread group ID, and exit code of the thread in the thread exit event. If the thread group ID already exists in the key of the "monitored role mapping table", it means that the exiting thread is part of a multi-tasking software system. Update the running status of the process in the role tree as follows:
[0342] If the thread ID of the exiting thread is the same as the thread group ID, it means that the exiting thread is a process, and the running status, exit code and exit time of the process in the "monitored role mapping table" are updated.
[0343] If the thread ID of the exiting thread is different from the thread group ID, it means that the exiting thread is a thread. Use the thread group ID of the exiting thread as the key value to find the corresponding process from the "monitored role mapping table" and update the thread running status, thread exit code and thread exit time of the corresponding thread in the thread list of the process.
[0344] The monitoring process can query detailed information of all current processes and threads of the multi-tasking software system by periodically calling the pidstat command. For example, the detailed information that can be queried includes: CPU usage, memory usage, thread name, CPU core number where the thread is located, thread running time and other information, and update the corresponding monitored role mapping table; among them, the pidstat command is a command of the sysstat software suite, which is used to monitor all or specified CPU, memory, and thread usage. Sysstat is a Linux system status monitoring tool that can be obtained from the software source of most Linux distributions.
[0345] In this implementation, the monitoring front-end interface selects the task platform to be monitored for monitoring connection, receives monitoring data from the task platform monitoring process in real time and constructs, displays, warns and controls it. The monitoring front-end interface receives the "monitored role mapping table" information sent by the monitoring process, and constructs a role tree with role No. 1 as the root node and resource roles and task roles as descendant nodes based on the parent-child relationship of the roles in the mapping table. Different colors are used to significantly distinguish different states of role nodes, such as Figure 7 As shown, green indicates that the role node is in normal operation, red indicates that the role node is in abnormal operation, and the CPU usage (CPU in the figure) and memory usage (MEM in the figure) of each role node are displayed in real time. Figure 8 As shown, for each role node, the right-click menu can display the "Role Details" window, which shows the detailed status of the role, such as CPU occupancy, memory usage, thread name (for example, thread1, ..., thread6 is used in the figure), the CPU core number of the thread, thread pid, thread running time and other information. For roles in abnormal status, the call stack information of the corresponding role node is displayed.
[0346] In one implementation, the process of obtaining call stack information corresponding to the abnormal signal according to the abnormal signal in the above step S2 may include:
[0347] According to the abnormal signal, a process identifier of the role where the abnormality occurs in the multi-task software system is obtained;
[0348] According to the process identifier of the role where the exception occurs, the call stack information corresponding to the exception signal is obtained;
[0349] For example, the call stack information may include: function name, executable program name, source code file name, and source code line number information.
[0350] In this implementation, the monitoring process uses the ptrace system call to track role No. 1. Other roles serve as their descendant processes. When they run abnormally, the monitoring process can capture the abnormal signal through waitpid and obtain the process PID number of the abnormal role.
[0351] Specifically, the process of obtaining the call stack information corresponding to the abnormal signal according to the process identifier of the role where the abnormality occurs may include:
[0352] Obtain the function name according to the process identifier of the role where the exception occurs in the multi-tasking software system;
[0353] Decode the function name to obtain the call stack function information corresponding to the function name;
[0354] According to the call stack function information, get the executable program name corresponding to the function name;
[0355] Disassemble the executable program name to obtain the static address corresponding to the function name;
[0356] According to the static address corresponding to the executable program name and the function name, the source code file information and source code line number information corresponding to the function name are obtained. In this implementation method, detailed call stack information including the function name, executable program (library) name, source code file name, and source code line number can be obtained.
[0357] For example, the monitoring process obtains the call stack information of the corresponding process (thread) by calling the libunwind library interface, and uses the abi::__cxa_demangle function to decode the function name. The call stack function information is as follows:
[0358] pid 16839stack:
[0359] 1)0x55ab06dcb27c:signal_11_error_fun3()+0x73
[0360] 2)0x55ab06dcb2ba:signal_11_error_fun2()+0x17
[0361] 3)0x55ab06dcb2d4:signal_11_error_fun1()+0xd
[0362] 4)0x55ab06dcb2e4:main+0xd
[0363] 5)0x7fa988dc50b3:__libc_start_main+0xf3
[0364] 6)0x55ab06dcb14e:_start+0x2e
[0365] Among them, libunwind is an open source C / C++ library that provides stack tracing capabilities, which is used to obtain call stack information of a process or thread at runtime; abi::__cxa_demangle is a function in the C++ runtime library used to decode (demangle) function names, which is used to restore the function names converted by the compiler to the original function names; pid 16839stack represents the call stack of process ID 16839; 0x55ab06dcb27c:signal_11_error_fun3()+0x73 is the top layer of the call stack, where 0x55ab06dcb27c represents the address of the function signal_11_error_fun3() in memory, and 0x73 indicates that the current execution point is 0x73 bytes away from the function entry; 0x55ab06dcb2ba:signal_11_error_fun2()+0x17 is the second layer of the call stack, where 0x55a b06dcb2ba indicates the address of the function signal_11_error_fun2() in memory, 0x17 indicates that the current execution point is 0x17 bytes away from the function entry; 0x55ab06dcb2d4:signal_11_error_fun1()+0xd is the third layer of the call stack, where 0x55ab06dcb2d4 indicates the address of the function signal_11_error_fun1() in memory; 0xd indicates that the current execution point is 0xd bytes away from the function entry; 0x55ab06dcb2e4:main+0x d is the fourth layer of the call stack. The main function is the starting point of the program, which indicates that a series of error handling functions are triggered by the main function. 0x55ab06dcb2e4 represents the address of the main function in memory. The current execution point 0xd is 0xd bytes away from the function entry. 0x7fa988dc50b3:__libc_start_main+0xf3 is the fifth layer of the call stack. __libc_start_main is a function provided by the glibc library. It is responsible for initializing the environment and calling the main function of the user program. 0xf3 indicates that in __libc_start_main The specific location in the bc_start_main function, 0x7fa988dc50b3 indicates the specific location of the function __libc_start_main in memory; 0x55ab06dcb14e:_start+0x2e is the bottom layer of the call stack, that is, the entry point of the program, 0x55ab06dcb14e indicates the specific location of the function _start in memory, _start is a symbol generated by the linker, indicating the start of the program, and 0x2e indicates the specific location within the _start function; with the above information, the specific path that causes the signal error can be traced.
[0366] For example, the above-mentioned process of obtaining the executable program (library) name based on the call stack function information may include the following process:
[0367] The monitoring process reads the contents of the / proc / ${pid} / maps file by calling it to determine the executable program (library) name corresponding to the function name. In this example, proc / ${pid} / maps describes the mapping of the file (executable program / library) to the memory area of the process. The / proc file system provides a pseudo-file system that reflects the current state of the kernel and process tree. / proc / ${pid} / maps represents the virtual memory layout of the process with process ID pid. The monitoring process first reads the / proc / ${pid} / maps file to obtain the memory mapping information (maps) of the process with process identifier pid. Based on the memory mapping information, the monitoring process checks the address of the function in the call stack to determine which program or library the function in the call stack comes from.
[0368] For example, the above-mentioned disassembly of the executable program name to obtain the static address corresponding to the function name may include the following process:
[0369] The obtained executable program (library) is disassembled using the objdump command, and the static address of the corresponding function is obtained from the disassembly result. The objdump command is a disassembly tool, commonly used in debugging and reverse engineering. It can be used to analyze the structure of binary files and output various information about object files, executable files, library files, etc. It can display the contents of these files in a human-readable format, including but not limited to assembly language code, symbol tables, relocation entries, section headers, etc. When using the objdump command to disassemble an executable program or library, it outputs the assembly language representation corresponding to the machine instructions of the program or library, which is helpful for understanding and debugging binary files, especially when the source code is not available or when in-depth analysis of the internal behavior of the binary file is required.
[0370] For example, the above-mentioned process of obtaining the source code file information and source code line number information corresponding to the function name based on the static address corresponding to the executable program name and the function name may include the following process:
[0371] Use the addr2line command to retrieve the actual source code file and the number of lines of code being run based on the executable program (library) name and the static address of the corresponding function. addr2line is a GNU debugging tool that maps memory addresses to source code line numbers, helping developers find problems when debugging applications. When using addr2line to retrieve source code locations, you must use the -g option when compiling the program to add debugging information to the compiled output file. Otherwise, no relevant information will be retrieved, and the output may display "??:?".
[0372] In one implementation, after performing abnormal location on the abnormal signal according to the call stack information in the above step S3 to obtain abnormal location information in the multi-tasking software system, the following steps may also be included:
[0373] Generate an exception response strategy based on the exception location information and preset user intervention instructions in the multi-tasking software system;
[0374] Perform emergency response on multi-task software systems based on abnormal response strategies.
[0375] In this implementation, the process of performing emergency response on the multi-task software system according to the abnormal response strategy may include:
[0376] When the abnormal response strategy is to restart the multi-task software system, emergency processing is performed on the multi-task software system by restarting role 1;
[0377] When the abnormal response strategy is to restart the role where the abnormality occurs, emergency processing is performed on the multi-task software system by restarting the role where the abnormality occurs.
[0378] Specifically, when an exception occurs in the multi-tasking software system of the present invention, multiple emergency response methods are supported based on different user intervention instructions and exception response strategies:
[0379] (1) If the abnormal response strategy is to restart the multi-task software system, the monitoring process restarts role 1 to restore the entire multi-task software system task, and counts the abnormal role information and the number of restarts of the multi-task software system to retain more field data during the stress test;
[0380] (2) If the exception response strategy is to restart the abnormal task role, the monitoring process sends a StartActor role startup instruction for the abnormal role to the task flow management role. The task flow management role calls the StartActor role startup interface to restart the task role based on the task status information maintained for the task role, so that the multi-task software system task resumes execution from the current task role.
[0381] (3) For task roles whose resource consumption exceeds the threshold or may cause deadlock (task process does not execute as expected, causing the debugger to pay attention), an interrupt intervention instruction is provided so that the debugger can view the current detailed call stack information of the role for subsequent performance analysis and process debugging. The implementation method is as follows:
[0382] ①The user sends an interruption intervention instruction;
[0383] ② After the monitoring process receives the user interrupt intervention instruction, it calls the "kill(pid,SIGSEGV)" system call to end the task role that requests interruption; among them, kill is a system call used to send a termination signal to one or a group of processes; pid represents the process identifier; SIGSEGV represents an abnormal signal. In the expression kill(pid,SIGSEGV), the monitoring process calls the kill system call to send a SIGSEGV signal to the process with PID pid.
[0384] ③ The monitoring process will capture the signal of abnormal termination of the task role through the waitpid system call and obtain the detailed call stack information of the task role;
[0385] In this embodiment, the existing monitoring method for multi-task software system needs to check each task process one by one when an exception occurs, which makes it difficult to quickly locate the problem. By proposing a monitoring method for multi-task software system based on role, such as Figure 9As shown, when role 1 is started, the process identifier (pid) of role 1 is sent to the monitoring process. After the monitoring process receives the pid of role 1, it tracks and monitors role 1, specifically including: monitoring abnormal signals of each role in the multi-tasking software system, monitoring role creation events, monitoring role stop events, building a role tree, obtaining detailed information of each role and obtaining the exception stack, and when an exception occurs, based on different user intervention instructions and exception response strategies, supporting multiple emergency handling methods, so that the multi-tasking software system task can resume execution from the current task role. In this embodiment, a multi-task software system is monitored based on a role tree, making it easier for debuggers to understand the global status of the multi-task software system. Specifically, a role tree is constructed and maintained with role 1 as the root node and resource roles and task roles as descendant nodes. The real-time status of all roles in the multi-task software system is intuitively displayed through a visual role tree, making it easier for debuggers to understand the global status of the multi-task software system. When monitoring the multi-task software system, only role 1 needs to be tracked to listen for exception signals from all roles in the multi-task software system. After an exception occurs, detailed call stack information is obtained to quickly locate the exception. The above method simplifies the exception capture process of the multi-task software system, eliminating the need to check the operating status of each role one by one, thereby improving system debugging efficiency and exception monitoring efficiency. In addition, this embodiment also adopts different exception response strategies during the exception monitoring process, supports multiple fault emergency handling methods, including multi-task software system-level fault recovery and task role-level exception recovery, and provides user interrupt intervention instructions to help debuggers quickly analyze system problems. This can significantly improve the stability and fault tolerance of the system, ensuring that the entire system can continue to operate even if some components or tasks fail.
[0386] Example 4:
[0387] The present invention based on the same inventive concept also provides a monitoring system for a multi-task software system based on a role, the structural composition diagram is shown in FIG. Figure 10 As shown, including:
[0388] Identifier acquisition module: used to obtain the process identifier of role No. 1 in the multi-tasking software system;
[0389] Abnormal monitoring module: used to monitor abnormal signals of No. 1 role, resource role and task role in the multi-task software system according to the process identifier of No. 1 role;
[0390] Information calling module: used to obtain the call stack information corresponding to the abnormal signal according to the abnormal signal; and locate the abnormal signal according to the call stack information to obtain the abnormal location information in the multi-tasking software system.
[0391] In a possible implementation, the exception monitoring module is specifically configured to:
[0392] According to the process identifier of role No. 1, get the process identifier of the descendant process corresponding to role No. 1;
[0393] According to the process identifier of role 1 and the process identifier of the descendant process corresponding to role 1, the process structure of role 1 and its descendant process is obtained, and the process structure of role 1 and its descendant process is added to the monitored role mapping table;
[0394] Track role 1 and start monitoring abnormal signals of role 1, resource roles, and task roles in the multi-tasking software system.
[0395] In a possible implementation, the process of adding the process structure of role 1 and its descendant processes to the monitored role mapping table in the exception monitoring module may include:
[0396] Use the process ID of the process identifier of role 1 and its descendant processes as the key, and the process structure corresponding to role 1 and its descendant processes as the value, and add the key and value to form a key-value pair and add it to the monitored role mapping table;
[0397] The process structure includes one or more of the following: process name, process ID, parent process ID, parent thread ID, process start and end time, process running status, process exit code, process CPU usage, process memory usage, process exit stack information and a list of all threads of the process.
[0398] In a possible implementation, the process of tracking role 1 and starting to monitor abnormal signals of role 1, resource roles, and task roles in the multi-task software system in the abnormal monitoring module may include:
[0399] By calling the ptrace system call, trace the No. 1 role and its descendant processes;
[0400] The waitpid system call is called according to a preset time period to obtain abnormal signals of role No. 1, resource role and task role in the multi-tasking software system.
[0401] In a possible implementation, the process of obtaining call stack information corresponding to the exception signal in the information calling module according to the exception signal may include:
[0402] According to the abnormal signal, a process identifier of the role where the abnormality occurs in the multi-task software system is obtained;
[0403] According to the process identifier of the role where the exception occurs, the call stack information corresponding to the exception signal is obtained;
[0404] The call stack information includes: function name, executable program name, source code file name and source code line number information.
[0405] In a possible implementation, the process of obtaining call stack information corresponding to the abnormal signal according to the process identifier of the role where the abnormality occurs in the information calling module may include:
[0406] Obtain the function name according to the process identifier of the role where the exception occurs in the multi-tasking software system;
[0407] Decode the function name to obtain the call stack function information corresponding to the function name;
[0408] According to the call stack function information, get the executable program name corresponding to the function name;
[0409] Disassemble the executable program name to obtain the static address corresponding to the function name;
[0410] According to the static address corresponding to the executable program name and the function name, the source code file information and source code line number information corresponding to the function name are obtained.
[0411] In a possible implementation, after the information calling module locates the exception signal according to the call stack information and obtains the exception location information in the multi-task software system, it may further include:
[0412] Generate an exception response strategy based on the exception location information and preset user intervention instructions in the multi-tasking software system;
[0413] Perform emergency response on multi-task software systems based on abnormal response strategies.
[0414] In one possible implementation, the process of performing emergency response on the multi-task software system in the information calling module according to the abnormal response strategy may include:
[0415] When the abnormal response strategy is to restart the multi-task software system, emergency processing is performed on the multi-task software system by restarting role 1;
[0416] When the abnormal response strategy is to restart the role where the abnormality occurs, emergency processing is performed on the multi-task software system by restarting the role where the abnormality occurs.
[0417] Example 5:
[0418] like Figure 11As shown, the present invention also provides an electronic device, which may be a computer, a single-chip microcomputer, a smart mobile device, or the like. The electronic device in this embodiment may include a processor, a memory, a transceiver component, and the like. The memory, processor, and transceiver component are connected via a bus; the memory may be used to store an execution program, which may include instructions; and the processor may be used to execute the instructions stored in the memory. The memory may also be used to store data, which may be accessed and / or modified during the execution of the instructions.
[0419] The processor may be a central processing unit (CPU), or it may be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. It is the computing core and control core of the terminal, which is suitable for implementing one or more instructions, specifically suitable for loading and executing one or more instructions in the storage medium to implement the corresponding method flow or corresponding function, so as to realize the steps of a method for constructing a role-based multi-tasking software system or a method for monitoring a role-based multi-tasking software system in the above-mentioned embodiment.
[0420] Example 6:
[0421] Based on the same inventive concept, the present invention also provides a readable storage medium, specifically an electronic device readable storage medium (Memory), which is a memory device in an electronic device for storing programs and data. It is understandable that the storage medium here can include both built-in storage media in the electronic device and, of course, extended storage media supported by the electronic device. The storage medium provides a storage space, which stores the operating system of the terminal. In addition, one or more instructions suitable for being loaded and executed by the processor are also stored in the storage space. These instructions can be one or more execution programs (including program codes). It should be noted that the storage medium here can be a high-speed RAM memory or a non-volatile memory, such as at least one disk memory. The processor loads and executes one or more instructions stored in the storage medium, which can implement the steps of a method for constructing a role-based multi-task software system or a method for monitoring a role-based multi-task software system in the above-mentioned embodiment.
[0422] It will be understood by those skilled in the art that embodiments of the present invention may be provided as methods, systems, or computer program products. Thus, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0423] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowcharts and / or block diagrams, as well as combinations of processes and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowcharts and / or block diagrams. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0424] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0425] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0426] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit its scope of protection. Although the present invention has been described in detail with reference to the above embodiments, ordinary technicians in the field should understand that after reading the present invention, those skilled in the art may still make various changes, modifications or equivalent substitutions to the specific implementation methods of the application, but these changes, modifications or equivalent substitutions are all within the scope of protection of the pending claims.
Claims
1. A method for constructing a role-based multi-task software system, characterized in that: include: Based on the multi-tasking software system startup instruction, start role No. 1; Start the resource role through the No. 1 role, and the resource role is used to provide resource services for the task role; The task roles include a task process management role and a task behavior execution role; the task process management role is used to manage the task behavior execution role; Based on the acquired task process startup requirements, obtain resource access tasks; The task behavior execution role is used to execute the resource access task; The task process management role is started through the No. 1 role, and based on the task process start-up requirement, the role name of the task behavior execution role to be started and the task status of the resource access task are obtained; Calling the StartActor role startup interface through the task process management role according to the role name of the task behavior execution role to be started and the task status of the resource access task; Reading the resource configuration file of the task behavior execution role through the resource role to obtain the requested resources required by the task behavior execution role when executing the resource access task; The resource configuration file includes: role name, requested resource and resource access mode; Obtaining a resource access data table for the resource role; the resource access data table includes: a resource identifier, a resource name, a resource access mode, an access role list, and a health level attribute; According to the resource access data table, a resource access mode corresponding to the requested resource is obtained; the resource access mode includes: resource sharing and resource exclusivity; When the resource access mode corresponding to the requested resource is resource sharing, the role name of the task behavior execution role is added to the access role list of the resource access data table, and resource allocation is performed on the requested resource; When the resource access mode corresponding to the requested resource is resource exclusive, check whether the access role list of the resource access data table is empty; if the access role list is not empty, add the role name of the task behavior execution role to the task role waiting queue; if the access role list is empty, allocate resources to the requested resource, and start the task behavior execution role corresponding to the role name according to the result of the resource allocation; The role No. 1 is taken as the root node, and the resource role and the task role are taken as descendant nodes to construct a role tree, thereby obtaining a role-based multi-task software system.
2. The method according to claim 1, wherein The starting of the resource role through the No. 1 role includes: Call the fork system call through the No. 1 role to create a startup child process; By calling the execlp system call through the No. 1 role, the created startup child process is replaced with the resource role process; The replaced startup sub-process is used to start the resource role.
3. The method according to claim 1, wherein The step of starting the task process management role through the No. 1 role includes: The first role listens to the task flow startup requirement and calls the fork system call to create an initial child process; By calling the execlp system call through the No. 1 role, the created initial child process is replaced with the task role management process; The task flow management role is started by using the replaced initial sub-process.
4. The method according to claim 1, wherein The step of starting the task process management role through the No. 1 role includes: Obtain the configuration file of role 1, read the configuration file through role 1, and call the fork system call to create a configuration child process; By calling the execlp system call through the No. 1 role, the created configuration sub-process is replaced with the task flow management process; The replaced configuration sub-process is used to start the task flow management role.
5. The method according to claim 1, wherein The step of starting the task behavior execution role corresponding to the role name according to the result of the resource allocation includes: When the resource allocation result shows that the requested resource is successfully allocated, the task flow management role calls a fork system call to create an execution child process; Calling the execlp system call through the task flow management role replaces the created execution sub-process with the process of the task behavior execution role; The replaced execution sub-process is used to start the task behavior execution role corresponding to the role name.
6. The method according to claim 5, wherein After starting the task behavior execution role corresponding to the role name, the method further includes: According to the obtained role name of the task behavior execution role to be stopped, the StopActor role stop interface is called through the task flow management role to stop the task behavior execution role.
7. The method according to claim 6, wherein The calling of the StopActor role stop interface by the task flow management role to stop the task behavior execution role includes: Calling the StopActor role stop interface through the task process management role; Reading the resource configuration file of the task behavior execution role to be stopped through the resource role to obtain the requested resources of the task behavior execution role to be stopped; According to the resource access data table of the resource role, the resource access mode corresponding to the requested resource of the task behavior execution role to be stopped is obtained; when the resource access mode corresponding to the requested resource is resource exclusive, the to-be-released resource associated with the task behavior execution role to be stopped is obtained, and it is checked whether the task role waiting queue contains a task behavior execution role requesting the to-be-released resource; if so, the role name of the task behavior execution role is deleted from the task role waiting queue, and the task behavior execution role is started; According to the resource access data table of the resource role, the role name of the task behavior execution role to be stopped is deleted from the access role list of the resource access data table; and a kill system call is called to stop the task behavior execution role.
8. A system for constructing a role-based multi-task software system, characterized in that: include: Task startup module: used to start role 1 based on the multi-task software system startup instruction; Resource management module: used to start the resource role through the No. 1 role, and the resource role is used to provide resource services for the task role; The task management module is used to obtain a resource access task based on the acquired task flow startup requirements, and to start a task role through the No. 1 role, and the task role is used to execute the resource access task; the No. 1 role is used as the root node, and the task roles are used as descendant nodes to construct a role tree, thereby obtaining a role-based multi-task software system; The task roles in the task management module include task process management roles and task behavior execution roles; Wherein, the task process management role is used to manage the task behavior execution role; The task behavior execution role is used to execute the resource access task; The step of starting the task role through the No. 1 role includes: Start the task process management role through the No. 1 role, and start the task behavior execution role through the task process management role; The task management module starts the task behavior execution role through the task process management role, including: Based on the task process startup requirement, the role name of the task behavior execution role to be started and the task status of the resource access task are obtained; According to the role name of the task behavior execution role to be started and the task status of the resource access task, the task process management role calls the StartActor role startup interface to start the task behavior execution role corresponding to the role name; The task management module calls the StartActor role startup interface through the task process management role to start the task behavior execution role corresponding to the role name, including: Call the StartActor role startup interface through the task process management role; Reading the resource configuration file of the task behavior execution role through the resource role to obtain the requested resources required by the task behavior execution role when executing the resource access task; the resource configuration file includes: role name, requested resources and resource access mode; Allocate the requested resources through the resource roles, and start the task behavior execution role corresponding to the role name according to the result of the resource allocation; The task management module allocates the requested resources according to the resource roles, including: Obtaining a resource access data table for the resource role; the resource access data table includes: a resource identifier, a resource name, a resource access mode, an access role list, and a health level attribute; According to the resource access data table, a resource access mode corresponding to the requested resource is obtained; the resource access mode includes: resource sharing and resource exclusivity; When the resource access mode corresponding to the requested resource is resource sharing, the role name of the task behavior execution role is added to the access role list of the resource access data table, and resource allocation is performed on the requested resource; When the resource access mode corresponding to the requested resource is resource exclusive, check whether the access role list of the resource access data table is empty. If the access role list is not empty, add the role name of the task behavior execution role to the task role waiting queue; if the access role list is empty, allocate resources to the requested resource.
9. A monitoring method for a role-based multi-task software system, characterized in that: include: Get the process identifier of role 1 in the multi-tasking software system; According to the process identifier of the No. 1 role, monitoring abnormal signals of the No. 1 role, resource roles and task roles in the multi-task software system; According to the abnormal signal, obtaining call stack information corresponding to the abnormal signal; Performing exception location on the exception signal according to the call stack information to obtain exception location information in the multi-task software system; Among them, the multi-task software system is a multi-task software system constructed by a role-based multi-task software system construction method according to any one of claims 1 to 7 above; the role No. 1 is the role No. 1 in the multi-task software system constructed by a role-based multi-task software system construction method according to any one of claims 1 to 7 above; the resource role is a resource role in the multi-task software system constructed by a role-based multi-task software system construction method according to any one of claims 1 to 7 above; the task role is a task role in the multi-task software system constructed by a role-based multi-task software system construction method according to any one of claims 1 to 7 above.
10. The method according to claim 9, wherein The monitoring of abnormal signals of the No. 1 role, the resource role, and the task role in the multi-task software system according to the process identifier of the No. 1 role includes: According to the process identifier of the No. 1 role, obtain the process identifier of the descendant process corresponding to the No. 1 role; Obtaining, according to the process identifier of the No. 1 role and the process identifiers of the descendant processes corresponding to the No. 1 role, a process structure of the No. 1 role and its descendant processes, and adding the process structure of the No. 1 role and its descendant processes to a monitored role mapping table; Track the No. 1 role and start monitoring abnormal signals of the No. 1 role, resource roles and task roles in the multi-task software system.
11. The method according to claim 10, wherein The step of adding the process structure of the No. 1 role and its descendant processes to the monitored role mapping table includes: Using the process ID of the process identifier of role 1 and its descendant processes as the key and the process structure corresponding to the role 1 and its descendant processes as the value, the key and value form a key-value pair and add it to the monitored role mapping table; The process structure includes one or more of the following: process name, process ID, parent process ID, parent thread ID, process start and end time, process running status, process exit code, process CPU occupancy, process memory occupancy, process exit stack information and a list of all threads of the process.
12. The method according to claim 11, wherein The step of tracking the No. 1 role and starting to monitor abnormal signals of the No. 1 role, resource roles, and task roles in the multi-task software system includes: By calling the ptrace system call, the process of tracing the role No. 1 and its descendant processes; The waitpid system call is called according to a preset time period to obtain abnormal signals of the No. 1 role, the resource role and the task role in the multi-task software system.
13. The method according to claim 9, wherein The obtaining, according to the abnormal signal, call stack information corresponding to the abnormal signal, includes: Obtaining, according to the abnormal signal, a process identifier of a role in the multi-task software system where the abnormality occurs; Obtaining call stack information corresponding to the abnormal signal according to the process identifier of the role where the abnormality occurs; The call stack information includes: function name, executable program name, source code file name and source code line number information.
14. The method according to claim 13, wherein The obtaining, according to the process identifier of the role where the exception occurs, call stack information corresponding to the exception signal includes: Obtaining a function name according to a process identifier of a role in which an exception occurs in the multi-tasking software system; Decode the function name to obtain call stack function information corresponding to the function name; Obtaining the executable program name corresponding to the function name according to the call stack function information; Disassembling the executable program name to obtain a static address corresponding to the function name; According to the executable program name and the static address corresponding to the function name, the source code file information and source code line number information corresponding to the function name are obtained.
15. The method according to claim 13, wherein After performing exception location on the abnormal signal according to the call stack information to obtain exception location information in the multi-task software system, the method further includes: generating an exception response strategy based on the exception location information and preset user intervention instructions in the multi-tasking software system; According to the abnormal response strategy, emergency processing is performed on the multi-task software system.
16. The method according to claim 15, wherein The performing emergency processing on the multi-task software system according to the abnormal response strategy includes: When the abnormal response strategy is to restart the multi-task software system, performing emergency processing on the multi-task software system by restarting the No. 1 role; When the abnormal response strategy is to restart the role where the abnormality occurs, emergency processing is performed on the multi-task software system by restarting the role where the abnormality occurs.
17. A monitoring system for a role-based multi-task software system, characterized in that: include: Identifier acquisition module: used to obtain the process identifier of role No. 1 in the multi-tasking software system; An abnormal monitoring module: used for monitoring abnormal signals of the No. 1 role, resource roles and task roles in the multi-task software system according to the process identifier of the No. 1 role; An information calling module is configured to obtain call stack information corresponding to the abnormal signal according to the abnormal signal; and to locate the abnormality of the abnormal signal according to the call stack information to obtain abnormality location information in the multi-tasking software system; Among them, the multi-task software system is a multi-task software system constructed by a role-based multi-task software system construction method according to any one of claims 1 to 7 above; the role No. 1 is the role No. 1 in the multi-task software system constructed by a role-based multi-task software system construction method according to any one of claims 1 to 7 above; the resource role is the resource role in the multi-task software system constructed by a role-based multi-task software system construction method according to any one of claims 1 to 7 above; the task role is the task role in the multi-task software system constructed by a role-based multi-task software system construction method according to any one of claims 1 to 7 above.
Citation Information
Patent Citations
Multi-Agent worksteam access control method based on improved role
CN104881736A
Lightweight distributed resource management and task scheduler and method
CN113515356A