Method and system for constructing and monitoring role-based multi-task software system
By constructing a character -based structure in multi -tasking software system, clarifying the internal calling relationship of the system, and providing rapid monitoring methods, the problems that cannot be monitored and quickly located in existing technologies have been solved. High -efficiency status monitoring and fault diagnosis.
Patent Information
- Application Number
- CN202411200194.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-29
- Publication Date
- 2025-01-28
- Estimated Expiration
- 2044-08-29
AI Technical Summary
Due to the unclear structure and call relationship of existing multitasks, the existing multitasks cannot grasp the status of all subtasks in real time, making it difficult to judge whether the system is operating normally. The monitoring methods are cumbersome and complex, so it is impossible to quickly discover exceptions and positioning problems.
Put forward a role -based multi -tasking software system construction method. Through the No. 1 character to start the resource role and task role, build a character tree, clarify the structure and call relationship of the system Monitoring methods, locate abnormalities in the system by monitoring the abnormal signal of the character No. 1.
A real -time status monitoring of multi -tasking software systems is realized, the problem of rapid positioning, improving the overall visibility and transparency of the system, and simplifying the fault diagnosis process.
Smart Images

Figure CN119376874A_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 uncertain complex environmental conditions, 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 environmental changes, capability requirements and other factors. However, the existing multi-task software systems are unclear in structure and calling relationships, making it impossible to grasp the status of all subtasks in real time and making it impossible to determine whether the system is operating normally;
[0003] Due to the uncertainty of the execution environment of multi-task software systems, the complexity of task coordination, and the increase in the size of collaborative development teams, it is difficult to monitor multi-task software systems in terms of task management, fault location, and abnormal recovery. The existing monitoring process for multi-task software systems includes fault analysis and debugging tools. For example, the gdb debugging tool is often used to debug a single potential abnormal target program, but the difficulty in debugging multi-task software systems happens to be that it is difficult for debuggers to locate which task may have an abnormality, and the execution flow generated by multiple concurrent processes (threads) is not the same every time, which means that the location of the system crash caused by the same bug may be different in several executions. Therefore, the existing monitoring method for multi-task software systems checks the running status of task processes (threads) one by one, which is cumbersome and complex, and cannot quickly discover abnormalities and locate problems. Summary of the invention
[0004] In order to solve the problem that the status of all subtasks cannot be grasped in real time due to unclear structure and calling relationship of the existing multitask software system, the present invention proposes a method for constructing a multitask software system based on roles, including:
[0005] Based on the multi-task software system startup instruction, start role No. 1;
[0006] Start the resource role through the role No. 1, and the resource role is used to provide resource services for the task role;
[0007] Based on the acquired task flow 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 No. 1 role 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 role No. 1 includes:
[0010] Calling the fork system call through the role No. 1 creates a startup child process;
[0011] By calling the execlp system call through the No. 1 role, the created startup subprocess is replaced with the resource role process;
[0012] The replaced startup subprocess 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 starting of the task role through the No. 1 role includes:
[0017] The task flow management role is started through the No. 1 role, and the task behavior execution role is started through the task flow management role.
[0018] Optionally, starting the task flow management role through the No. 1 role includes:
[0019] The task flow startup requirement is monitored by the role No. 1, and the fork system call is called 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 flow management role through the No. 1 role includes:
[0023] Obtain the configuration file of role No. 1, read the configuration file through role No. 1, and call the fork system call to create a configuration subprocess;
[0024] By calling the execlp system call through the No. 1 role, the created configuration subprocess 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 flow management role includes:
[0027] Based on the task flow startup requirement, obtain the role name of the task behavior execution role to be started and the task status of the resource access task;
[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 task behavior execution role corresponding to the role name is started by calling the StartActor role startup interface through the task flow management role.
[0029] Optionally, calling the StartActor role start interface through the task flow management role to start the task behavior execution role corresponding to the role name includes:
[0030] Calling the StartActor role startup interface through the task flow management role;
[0031] 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;
[0032] The requested resource is allocated through the resource role, 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 by using the resource role includes:
[0034] Obtaining a resource access data table of 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 the fork system call to create an execution subprocess;
[0040] Calling the execlp system call through the task flow management role replaces the created execution subprocess 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 through the task flow management role to stop the task behavior execution role includes:
[0045] Calling the StopActor role stop interface through the task flow management role;
[0046] Reading a resource configuration file of the task behavior execution role to be stopped through the resource role, and obtaining a request resource 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 the 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 start module: used to start role 1 based on the multi-task software system start 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 flow 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] Calling the fork system call through the role No. 1 creates a startup child process;
[0055] By calling the execlp system call through the No. 1 role, the created startup subprocess is replaced with the resource role process;
[0056] The replaced startup subprocess 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 starting of the task role through the No. 1 role includes:
[0061] The task flow management role is started through the No. 1 role, and the task behavior execution role is started through the task flow management role.
[0062] Optionally, in the task management module, starting the task flow management role through the No. 1 role includes:
[0063] The task flow startup requirement is monitored by the role No. 1, and the fork system call is called 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, in the task management module, starting the task flow management role through the No. 1 role includes:
[0067] Obtain the configuration file of role No. 1, read the configuration file through role No. 1, and call the fork system call to create a configuration subprocess;
[0068] By calling the execlp system call through the No. 1 role, the created configuration subprocess 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, in the task management module, starting the task behavior execution role through the task flow management role includes:
[0071] Based on the task flow startup requirement, obtain the role name of the task behavior execution role to be started and the task status of the resource access task;
[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 task behavior execution role corresponding to the role name is started by calling the StartActor role startup interface through the task flow management role.
[0073] Optionally, in the task management module, calling the StartActor role start interface through the task flow management role to start the task behavior execution role corresponding to the role name includes:
[0074] Calling the StartActor role startup interface through the task flow management role;
[0075] 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;
[0076] The requested resource is allocated through the resource role, 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 of 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 the fork system call to create an execution subprocess;
[0084] Calling the execlp system call through the task flow management role replaces the created execution subprocess 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 flow management role;
[0090] Reading a resource configuration file of the task behavior execution role to be stopped through the resource role, and obtaining a request resource 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 the 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 monitoring method for a role-based multi-task software system, comprising:
[0094] Get the process identifier of role No. 1 in the multi-tasking software system;
[0095] According to the process identifier of the role No. 1, monitoring the abnormal signals of the role No. 1, the resource role and the task role in the multi-task software system;
[0096] According to the abnormal signal, obtaining call stack information corresponding to the abnormal signal;
[0097] Performing an exception location on the abnormal signal according to the call stack information to obtain the 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] According to the process identifier of the No. 1 role and the process identifier of the descendant process corresponding to the No. 1 role, the process structure of the No. 1 role and its descendant process is obtained, and the process structure of the No. 1 role and its descendant process is added to the 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 number of the process identifier of the No. 1 role and its descendant processes as the key, and the process structure corresponding to the No. 1 role 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, 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:
[0107] By calling the ptrace system call, the role No. 1 and its descendant processes are tracked;
[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 abnormal signal according to the abnormal signal includes:
[0110] According to the abnormal signal, a process identifier of a role in the multi-task software system where an abnormality occurs is obtained;
[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 abnormality occurs in the multi-task software system;
[0115] Decoding 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 abnormal response strategy according to the abnormal location information and the preset user intervention instructions in the multi-task 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, emergency processing is performed 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-task software system;
[0127] An abnormal monitoring module: used for monitoring 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;
[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 abnormal 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] According to the process identifier of the No. 1 role and the process identifier of the descendant process corresponding to the No. 1 role, the process structure of the No. 1 role and its descendant process is obtained, and the process structure of the No. 1 role and its descendant process is added to the 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 number of the process identifier of the No. 1 role and its descendant processes as the key, and the process structure corresponding to the No. 1 role 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 to monitor 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 role No. 1 and its descendant processes are tracked;
[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] According to the abnormal signal, a process identifier of a role in the multi-task software system where an abnormality occurs is obtained;
[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 the 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 abnormality occurs in the multi-task software system;
[0145] Decoding 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 the exception location information in the multi-task software system, the information calling module further includes:
[0150] generating an abnormal response strategy according to the abnormal location information and the preset user intervention instructions in the multi-task 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, emergency processing is performed 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, 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 is implemented.
[0158] On the other hand, the present invention also provides a computer-readable storage medium having a computer program stored thereon, which, when executed, 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: based on a multi-task software system startup instruction, starting role No. 1; starting a resource role through role No. 1, wherein the resource role is used to provide resource services for the task role; based on the acquired task flow startup requirements, obtaining a resource access task, starting a task role through role No. 1, wherein the task role is used to execute the resource access task; taking role No. 1 as a root node, taking the resource role and the task role as descendant nodes, constructing a role tree, and obtaining a role-based multi-task software system; when constructing a multi-task software system, the present application starts role No. 1, and starts resource roles and task roles through role No. 1, clarifies the calling relationship within the system, takes role No. 1 as the root node of the multi-task software system, and takes resource roles and task roles as descendant nodes of the multi-task software system, clarifies the structural relationship within the multi-task software system, so that the multi-task software system constructed by the present invention can clarify the structure and calling relationship within the system, and monitor the status changes of subtasks in real time.
[0161] 2. The present invention provides a monitoring method and system for a role-based multi-task software system, comprising: obtaining a process identifier of role No. 1 in the multi-task software system; monitoring abnormal signals of role No. 1, resource roles and task roles in the multi-task software system according to the process identifier of role No. 1; obtaining call stack information corresponding to the abnormal signal according to the abnormal signal; locating the abnormal signal according to the call stack information to obtain abnormal location information in the multi-task software system; the present application can monitor the global operating status of the multi-task software system by tracking role No. 1, without checking the operating status of each role one by one, which is conducive to improving the efficiency of abnormal monitoring of the software system. 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 of a role-based multi-task software system provided by the present invention;
[0165] Figure 4 A flowchart of a monitoring method for a role-based multi-task software system 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-task software system provided by the present invention;
[0168] Figure 7 An example diagram of monitoring of a role tree displayed on a monitoring front end in a monitoring method of 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] Fig. 9 A schematic diagram of overall monitoring interaction in a monitoring method for a role-based multi-task software system provided by the present invention;
[0171] Fig.10 A schematic diagram of the structure of a monitoring system for a role-based multi-task software system provided by the present invention;
[0172] Fig.11 The present invention provides a schematic structural diagram of an electronic device. DETAILED DESCRIPTION
[0173] The present invention proposes a method and system for constructing and monitoring a role-based multi-task software system. The specific implementation of the present invention is further described in detail below in conjunction with the accompanying drawings.
[0174] Embodiment 1:
[0175] A method for constructing a role-based multi-task software system, the flowchart is as follows Figure 1 As shown, including:
[0176] Step 1: Based on the multi-task 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 acquired task flow startup requirements, obtain the resource access task, and start the task role through role No. 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 the descendant nodes, build a role tree, and obtain a role-based multi-task software system.
[0180] In general, in the existing multi-task software system, especially the robot multi-task software system, in a multi-core CPU (Central Processing Unit) environment, by creating multiple processes, each process can run independently on a different CPU core to make full use of hardware resources, and the processes are relatively isolated, but the communication overhead is large, and due to the unclear structure and call relationship within the system, it becomes difficult to grasp the status of all subtasks in real time and judge whether the system is operating normally. Some dynamically created subtasks may terminate abnormally and it is difficult to detect, and the number of software developers involved is huge. When an abnormality occurs, a lot of manpower and time need to be invested to check each software module one by one, and it is difficult to quickly locate the cause of the problem. In view of the management and monitoring difficulties faced by the above multi-task software system, the present invention constructs a role-based multi-task software system by taking role No. 1 as the root node and taking 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, and specifically the multi-task software system is a specific task process running on an individual platform. The multi-task software system constructed based on the above role is conducive to task-oriented resource management, and can be conducive to the rapid location of faults occurring during system operation and emergency processing such as abnormal recovery.
[0181] Specifically, Figure 2As shown, the multi-task software system constructed by the construction method in this embodiment is constructed by three types of roles, namely, role 1, resource role, and task role, wherein role 1 and resource role are static roles, which are created when the system starts, and task role is a dynamic role, which is dynamically created according to the task flow 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, and all roles of the multi-task software system exit when role 1 stops; 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., which helps to optimize resource allocation, manage resource conflicts, and improve resource utilization, thereby improving the performance of the entire system. Resource role provides 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 flow management role and task behavior execution role, and 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 software system's abnormality monitoring efficiency.
[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 subprocess 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 No. 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 No. 1 may include:
[0193] Role 1 listens to the task flow startup requirements and calls the fork system call to create the initial child process;
[0194] The execlp system call is called by role 1 to replace the created initial child process with the task role management process;
[0195] The replaced initial subprocess is used to start the task flow management role.
[0196] In this implementation, the above-mentioned starting the task flow management role through role No. 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 and stop method: (1) start and stop the task process management role; (2) start and stop the task behavior execution role; by independently controlling the start and stop of these two types of task roles, the use of resources can be managed more finely. Resources are dynamically applied for and released in units of roles, 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.
[0201] For example, the process of starting and stopping the task flow management role may be: reading a configuration file or listening to a remote task flow startup requirement through role No. 1, wherein the configuration file is configured with the name of the task flow 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 flow 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 flow 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" and "task status" to be started; the "task status" parameter describes the startup status of the task. When an abnormality occurs in the behavior execution role and emergency processing is required, the execution can be resumed according to the task status.
[0210] In this implementation, the process of calling the StartActor role start 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 start 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 executing 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 above process of allocating requested resources by resource roles may include:
[0215] Obtain a resource access data table of 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] According to the resource access data table, a resource access mode corresponding to the requested resource is obtained; 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 for the requested resource; in this implementation method, the present invention provides a resource management interface for the task flow 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 for the task flow management role and the task behavior execution role, resources are dynamically applied for and released in units of roles, 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 fork system call is called through the task flow management role to create an execution child process;
[0221] Call the execlp system call through the task flow management role to replace the created execution subprocess with the process of the task behavior execution role;
[0222] Use the replaced execution subprocess 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 StopActor role stop interface is called through the task process management role 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 the string type; actor_name indicates the role name; the task flow management role stops the interface by calling the StopActor role, 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 flow management role and stopping 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, and obtain the request resource 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 in 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 a resource management interface (such as StartActor and StopActor interfaces) for the task flow management role to start and stop the task behavior execution role, and when the task flow management role is started, according to different access modes of resources, it arbitrates and allocates resources for the task behavior execution role; when the role is stopped, it releases resources. The specific process may include the following contents:
[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 may 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] The shared access mode allows multiple roles to use the resource at the same time. For example, the access mode of the requested resource ID: dev0 corresponding to the sensor with the resource name sensor1 is shared access. It is being used by roles actor1, actor2, and actor3, and the health level of the resource dev0 is 10.
[0239] The exclusive access mode only allows 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 with the resource name controller2 is exclusive access, and it is being used by the role actor1, and 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] Role 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 behavior 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 for the time being, 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 flow 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 starting 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 at the problem that the status of all subtasks cannot be grasped in real time due to unclear structure and call relationship of the existing multi-task software system, and proposes a construction method of a multi-task software system based on roles, taking role No. 1 as the root node, resource role and task role as descendant nodes, and constructing the multi-task software system through three types of roles, and based on the multi-task software system startup instruction, starting role No. 1, and starting the resource role and the task role corresponding to the task process startup requirement through role No. 1, clarifying the structure and call relationship inside the system, in addition, the present invention also provides a two-level start-stop mode of the task process management role and the task behavior execution role, dynamically applying for and releasing resources in units of roles, performing resource arbitration and allocation when the task role is started, and releasing resources when the task role is stopped, completing resource conflict management, so that the present invention can perform resource management for tasks, 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 is conducive to real-time monitoring of the state changes of subtasks by clarifying the structure and call relationship inside the system based on roles, thereby improving the overall visibility and transparency of the system, and when a system failure occurs, the role-based structure helps to quickly locate the role and subtask where the problem is located, reducing the fault diagnosis time.
[0259] Embodiment 2:
[0260] The present invention based on the same inventive concept also provides a system for constructing a role-based multi-task software system, the structural composition diagram is shown in FIG. Figure 3 As shown, including:
[0261] Task start module: used to start role 1 based on the multi-task software system start instruction;
[0262] Resource management module: used to start the resource role through role 1. The resource role is used to provide resource services for the task role.
[0263] Task management module: used to start the demand based on the acquired task flow, obtain the resource access task, start the task role through role No. 1, and the task role is used to perform the resource access task; take role No. 1 as the root node and the task role as the descendant node, 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 No. 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 subprocess; 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 No. 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] Role 1 listens to the task flow startup requirements and calls the fork system call to create the initial child process;
[0275] The execlp system call is called by role 1 to replace the created initial child process with the task role management process;
[0276] The replaced initial subprocess is used to start the task flow 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 subprocess to start the task flow management role.
[0281] In a possible implementation, the process of starting 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 start interface through the task flow management role to start the task behavior execution role corresponding to the role name may include:
[0285] Call the StartActor role start 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 by resource roles in the task management module may include:
[0289] Obtain a resource access data table of a resource role; the 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 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.
[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 result of resource allocation may include:
[0294] When the resource allocation result shows that the requested resources are successfully allocated, the fork system call is called through the task flow management role to create an execution child process;
[0295] Call the execlp system call through the task flow management role to replace the created execution subprocess with the process of the task behavior execution role;
[0296] Use the replaced execution subprocess 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 StopActor role stop interface is called through the task process management role 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, and obtain the request resource 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] Embodiment 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 is as follows: Figure 4 As shown, including:
[0306] Step S1: Obtain the process identifier of role No. 1 in the multi-task software system;
[0307] Step S2: According to the process identifier of role No. 1, monitoring the abnormal signals of role No. 1, resource role and task role in the multi-task software system;
[0308] Step S3: according to the abnormal signal, obtain the call stack information corresponding to the abnormal signal; and perform abnormal location on the abnormal signal according to the call stack information to obtain the abnormal location information in the multi-task software system;
[0309] Among them, the multi-task software system is a multi-task software system constructed by a role-based multi-task software system construction method as mentioned above; role No. 1 is role No. 1 in a multi-task software system constructed by a role-based multi-task software system construction method as mentioned above; the resource role is a resource role in a multi-task software system constructed by a role-based multi-task software system construction method; and the task role is a task role in a multi-task software system constructed by a 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, for example, be 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, obtain the process identifier of the descendant process corresponding to role No. 1;
[0313] According to the process identifier of role No. 1 and the process identifier of the descendant process corresponding to role No. 1, the process structure of role No. 1 and its descendant process is obtained, and the process structure of role No. 1 and its descendant process is added to the monitored role mapping table;
[0314] Track role 1 and start monitoring abnormal signals of 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] Taking 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 form a key-value pair and add it 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 rate, process memory occupancy rate, 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:
[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 indicates that the key type of the associative container std::map is pid_t, and the 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 No. 1 and starting to monitor abnormal signals of role No. 1, resource roles, and task roles in the multi-task software system may include:
[0321] By calling the ptrace system call, role 1 and its descendant processes are tracked;
[0322] 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-task 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 is terminated or suspended, waitpid returns the pid number of the child process and provides information about the status of the child process; specifically, the implementation method calls the ptrace system call through the monitoring process, tracks role No. 1 and starts to monitor abnormal signals of other roles, and 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 track 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, the role of PTRACE_O_TRACEFORK is: 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 it is for the clone system call. The clone system call allows the creation of a child process that shares some 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 will automatically trace all child processes created by role No. 1 through fork system call or clone system call, which is very useful for debugging complex multi-process applications, and the PTRACE_O_TRACEFORK and PTRACE_O_TRACECLONE options only need to be set for role No. 1, and the newly created child process (thread) will inherit the option after automatic tracing, without the need to set the option for other task roles.
[0328] ③ Periodically call the waitpid system call to wait for abnormal signals from role 1 and child processes. 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, and its initial value is -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 system, which is used to wait for the termination or suspension status of the child process. When the child process is terminated or suspended, waitpid will return the pid number of the child process and provide information about the status of the child process; &status is a pointer to the status variable, which is an integer variable. Waitpid will store the status information of the child process in this variable. For example, the status information may include whether the child process terminates normally, whether it terminates due to receiving a signal, whether it is suspended or continued, etc.; WNOHANG is a flag. When used with waitpid, it 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 in the default case, waiting for the change of the child process status. This allows the caller to periodically check the status of the child process 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 it is 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, which 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-task software system, it is still necessary to set the system administrator (root) authority and process tracking authority for the monitoring process. The authority (Capablity) mechanism of the Linux system can be used to set the authority for the monitoring process. The example is as follows (assuming that 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 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 of Capabilities, which is used to control the permissions that a process has during its execution; / xxx / xxx / monitor_node represents the full path of the monitoring process monitor_node; in summary, this command means: run the setcap command with root privileges, grant the three Capabilities permissions of cap_net_raw, cap_net_admin and cap_sys_ptrace to the monitoring process / xxx / xxx / monitor_node, and ensure that these permissions take effect when the process is executed. This is done to allow 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 to the system thread creation event (proc_event::PROC_EVENT_FORK) and thread exit event (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 monitoring 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 related 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) Get 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 a 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) Get 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 the 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 occupancy, memory occupancy, thread name, CPU core number of the thread, thread running time and other information, and update it to 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 occupancy. Sysstat is a Linux system status monitoring tool, which 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 role parent-child relationship in the mapping table. Different colors are used to significantly distinguish different states of role nodes, such as Figure 7 As shown in the figure, green indicates that the role node is in normal operation, and red indicates that the role node is in abnormal operation. It also displays the CPU usage (represented by CPU in the figure) and memory usage (represented by MEM in the figure) of each role node 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 above call stack information may include: function name, executable program name, source code file name and source code line number information.
[0350] In this implementation, after the monitoring process uses the ptrace system call to track role No. 1, other roles are its 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 a function name according to a process identifier of a role that has an abnormality in a multi-task 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, and obtains the call stack function information 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 functions, which is used to obtain the 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. 0xd is the current execution point 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 __li 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 beginning of the program, and 0x2e indicates the specific location in the _start function; through 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 according to 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 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 by the objdump command, and the static address of the corresponding function is obtained from the disassembly result; the objdump command is a disassembly tool, usually used in debugging and reverse engineering, which can be used to analyze the structure of binary files and output various information of 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 the objdump command is used to disassemble an executable program or library, it will output the assembly language representation corresponding to the machine instructions of the program or library, which is conducive to understanding and debugging binary files, especially when there is no source code or the internal behavior of the binary file needs to be analyzed in depth.
[0370] For example, the above-mentioned process of obtaining source code file information and source code line number information corresponding to a function name according to the static address corresponding to the executable program name and the function name may include the following process:
[0371] The addr2line command can be used to obtain 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 used to map memory addresses to source code line numbers, helping developers find problems when debugging applications. When using addr2line to obtain the source code location, the -g option must be used when compiling the program to add debugging information to the compiled output file, otherwise no relevant information can be obtained and the result 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 the abnormal location information in the multi-task software system, the following may also be included:
[0373] Generate an exception response strategy based on the exception location information and preset user intervention instructions in the multi-task 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 processing 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 No. 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-task 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 No. 1 to restore the entire multi-task software system task, and counts the abnormal role information and the number of multi-task software system restarts, so as 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 (the task process does not execute as expected, causing the debugger to pay attention), interrupt intervention instructions are 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 the interrupt; 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 end 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 roles, such as Fig. 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-task 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-task software system task can be resumed from the current task role. In this embodiment, the multi-task software system is monitored based on the role tree, which is convenient for debuggers to grasp the global state of the multi-task software system. Specifically, a role tree with role No. 1 as the root node and resource roles and task roles as descendant nodes is constructed and maintained. The real-time state of all roles of the multi-task software system is intuitively displayed through the visual role tree, which is convenient for debuggers to grasp the global state of the multi-task software system. When monitoring the multi-task software system, only role No. 1 needs to be tracked to monitor the abnormal signals of all roles of the multi-task software system, and its detailed call stack information can be obtained after the abnormality occurs, and the abnormality is quickly located. The above method can simplify the abnormality capture process of the multi-task software system, without checking the running state of each role one by one, and improve the system debugging efficiency and abnormality monitoring efficiency; and this embodiment also adopts different abnormal response strategies in the process of abnormal monitoring, supports multiple fault emergency processing methods, including multi-task software system-level fault recovery and task role-level abnormal recovery, and provides user interrupt intervention instructions to help debuggers quickly analyze system problems, which can significantly improve the stability and fault tolerance of the system, and ensure that the system as a whole can continue to run even when some components or tasks fail.
[0386] Embodiment 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. Fig.10 As shown, including:
[0388] Identifier acquisition module: used to obtain the process identifier of role No. 1 in the multi-task 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-task software system.
[0391] In a possible implementation, the exception monitoring module is specifically used to:
[0392] According to the process identifier of role No. 1, obtain the process identifier of the descendant process corresponding to role No. 1;
[0393] According to the process identifier of role No. 1 and the process identifier of the descendant process corresponding to role No. 1, the process structure of role No. 1 and its descendant process is obtained, and the process structure of role No. 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-task 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] 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 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 occupancy, process memory occupancy, process exit stack information and a list of all threads of the process.
[0398] In a possible implementation, the process of tracking role No. 1 and starting to monitor abnormal signals of role No. 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, role 1 and its descendant processes are tracked;
[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-task software system.
[0401] In a possible implementation, the process of obtaining call stack information corresponding to the abnormal signal in the information calling module according to the abnormal 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 a function name according to a process identifier of a role that has an abnormality in a multi-task 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-task software system;
[0413] Perform emergency response on multi-task software systems based on abnormal response strategies.
[0414] In a possible implementation, the process of performing emergency processing 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 No. 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] Embodiment 5:
[0418] like Fig.11As shown, the present invention also provides an electronic device, which may be a computer device, a single-chip device, an intelligent mobile device, etc. The electronic device in this embodiment may include a processor, a memory, a transceiver component, etc. The memory, the processor, and the transceiver component are connected via a bus; the memory may be used to store an execution program, and an exemplary execution program may include instructions; the processor is used to execute the instructions stored in the memory. The memory may also be used to store data, which may be called and / or modified when the instructions are executed.
[0419] The processor may be a central processing unit (CPU), or 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 a storage medium to implement corresponding method flows or corresponding functions, so as to implement a method for constructing a role-based multi-task software system or a step of a monitoring method for a role-based multi-task software system in the above-mentioned embodiment.
[0420] Embodiment 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 can be understood 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, and 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] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, 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 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 flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, 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 flowchart and / or block diagram. 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 capable of directing a computer or other programmable data processing device to operate 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 A 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 operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified 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 rather than to limit its protection scope. 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 can 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 protection scope of the claims to be approved.
Claims
1. A method for constructing a role-based multi-task software system, characterized in that: include: Based on the multi-task software system startup instruction, start role No. 1; Start the resource role through the role No. 1, and the resource role is used to provide resource services for the task role; Based on the acquired task flow 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; The No. 1 role 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, characterized in that The starting of the resource role through the role No. 1 includes: Calling the fork system call through the role No. 1 creates a startup child process; By calling the execlp system call through the No. 1 role, the created startup subprocess is replaced with the resource role process; The replaced startup subprocess is used to start the resource role.
3. The method according to claim 1, characterized in that The task roles 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 starting of the task role through the No. 1 role includes: The task flow management role is started through the No. 1 role, and the task behavior execution role is started through the task flow management role.
4. The method according to claim 3, characterized in that The step of starting the task flow management role through the role No. 1 includes: The task flow startup requirement is monitored by the role No. 1, and the fork system call is called 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.
5. The method according to claim 3, characterized in that The step of starting the task flow management role through the role No. 1 includes: Obtain the configuration file of role No. 1, read the configuration file through role No. 1, and call the fork system call to create a configuration subprocess; By calling the execlp system call through the No. 1 role, the created configuration subprocess is replaced with the task flow management process; The replaced startup sub-process is used to start the task flow management role.
6. The method according to claim 3, characterized in that The step of starting the task behavior execution role through the task flow management role includes: Based on the task flow startup requirement, obtain the role name of the task behavior execution role to be started and the task status of the resource access task; 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 behavior execution role corresponding to the role name is started by calling the StartActor role startup interface through the task flow management role.
7. The method according to claim 6, characterized in that The calling of the StartActor role start interface by the task flow management role to start the task behavior execution role corresponding to the role name includes: Calling the StartActor role startup interface through the task flow management role; 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; The requested resource is allocated through the resource role, and according to the result of the resource allocation, the task behavior execution role corresponding to the role name is started.
8. The method according to claim 7, characterized in that The allocating the requested resource by using the resource role includes: Obtaining a resource access data table of 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. The method according to claim 8, characterized in that 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 the fork system call to create an execution subprocess; Calling the execlp system call through the task flow management role replaces the created execution subprocess 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.
10. The method according to claim 9, characterized in that 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.
11. The method according to claim 10, characterized in that 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 flow management role; Reading a resource configuration file of the task behavior execution role to be stopped through the resource role, and obtaining a request resource 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 the kill system call is called to stop the task behavior execution role.
12. A system for constructing a role-based multi-task software system, characterized in that: include: Task start module: used to start role 1 based on the multi-task software system start 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; Task management module: used to obtain resource access tasks based on the acquired task flow startup requirements, and start the task role through the No. 1 role, and the task role is used to execute the resource access task; The No. 1 role is taken as the root node, and the task roles are taken as descendant nodes to construct a role tree, thereby obtaining a role-based multi-task software system.
13. A monitoring method for a role-based multi-task software system, characterized in that: include: Get the process identifier of role No. 1 in the multi-tasking software system; According to the process identifier of the role No. 1, monitoring the abnormal signals of the role No. 1, the resource role and the task role in the multi-task software system; According to the abnormal signal, obtaining call stack information corresponding to the abnormal signal; Performing an exception location on the abnormal signal according to the call stack information to obtain the exception location information in the multi-task software system; Among them, the multi-task software system is a multi-task software system constructed by any one of claims 1 to 11 above; the role No. 1 is the role No. 1 in the multi-task software system constructed by any one of claims 1 to 11 above; the resource role is the resource role in the multi-task software system constructed by any one of claims 1 to 11 above; the task role is the task role in the multi-task software system constructed by any one of claims 1 to 11 above.
14. The method according to claim 13, characterized in that 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; According to the process identifier of the No. 1 role and the process identifier of the descendant process corresponding to the No. 1 role, the process structure of the No. 1 role and its descendant process is obtained, and the process structure of the No. 1 role and its descendant process is added to the 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.
15. The method according to claim 14, characterized in that 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 number of the process identifier of the No. 1 role and its descendant processes as the key, and the process structure corresponding to the No. 1 role 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.
16. The method according to claim 15, characterized in that 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 role No. 1 and its descendant processes are tracked; 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.
17. The method according to claim 13, characterized in that The obtaining, according to the abnormal signal, call stack information corresponding to the abnormal signal, comprises: According to the abnormal signal, a process identifier of a role in the multi-task software system where an abnormality occurs is obtained; 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.
18. The method according to claim 17, characterized in that 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 abnormality occurs in the multi-task software system; Decoding 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.
19. The method according to claim 17, characterized in that After locating the abnormal signal according to the call stack information to obtain the abnormal location information in the multi-task software system, the method further includes: generating an abnormal response strategy according to the abnormal location information and the preset user intervention instructions in the multi-task software system; According to the abnormal response strategy, emergency processing is performed on the multi-task software system.
20. The method of claim 19, 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, emergency processing is performed 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.
21. 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-task software system; An abnormal monitoring module: used for monitoring 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; 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.
Citation Information
Patent Citations
Method for monitoring and controlling subprocess based on Linux system
CN101630262A
Multi-Agent worksteam access control method based on improved role
CN104881736A
Authority management method, management server, service server and readable storage medium
CN112926068A
Heterogeneous group unmanned system cooperative task management system based on group role
CN112987778A
Lightweight distributed resource management and task scheduler and method
CN113515356A