Method and system for monitoring process state by adopting watchdog mechanism and computer program product
By using watchdog mechanism and Redis for process status monitoring in embedded computing systems, the problems of data competition and deadlock in traditional shared memory methods are solved, system stability is improved and distributed deployment is supported.
Patent Information
- Application Number
- CN202411327929.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-23
- Publication Date
- 2025-02-14
AI Technical Summary
In traditional embedded computing systems, shared memory is used for process status monitoring, which is prone to data competition and deadlock problems, resulting in poor system stability.
The watchdog mechanism is used to monitor the process status through Redis. Each business process creates a heartbeat key in Redis and regularly updates its TTL. The monitoring service process continuously detects whether the heartbeat key exists. If it does not exist, it will be processed as an abnormal exit.
Redis is a middleware for data interaction between multiple processes, data competition and deadlock problems in shared memory are avoided, system stability is improved, and distributed deployment and scaling is supported.
Smart Images

Figure CN119440892A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of process status monitoring, and in particular to a method, system and computer program product for monitoring process status by using a watchdog mechanism. Background Art
[0002] In an embedded computing system, there are generally multiple business processes and one management process, wherein the management process is used to monitor the status of each business process and restart the process if there is an abnormality.
[0003] The traditional method uses a shared memory method. Each business process periodically writes its own heartbeat data to the shared memory. The management process determines whether the status of each process is abnormal based on whether the heartbeat data is updated. If it is abnormal, the process is restarted.
[0004] In traditional methods, shared memory is used as the middleware for process interaction. Since multiple processes may access shared memory at the same time, problems such as data contention and deadlock may occur easily, resulting in poor system stability. Summary of the invention
[0005] The present invention provides a method, system and computer program product for monitoring process status by using a watchdog mechanism, thereby avoiding the problems of data competition and deadlock in a shared memory and improving system stability.
[0006] According to a first aspect of an embodiment of the present invention, a method for monitoring a process state using a watchdog mechanism is provided, which is applied to a system that monitors a process state using a watchdog mechanism, wherein the system includes at least one business process, at least one monitoring service process, and Redis, and the method includes:
[0007] When the first business process is initialized, the first business process writes a target heartbeat key named with a unique identifier to Redis, and sets a TTL for the target heartbeat key; wherein the first business process represents any one of the at least one business process;
[0008] Redis stores the target heartbeat key;
[0009] When the first business process is running, the TTL is updated periodically;
[0010] Redis receives the TTL updated by the first business process;
[0011] The first monitoring service process monitors whether a target heartbeat key exists in Redis; wherein the first monitoring service process represents a process in at least one monitoring service process that monitors the first business process.
[0012] In a possible implementation, the method further includes:
[0013] When the first business process ends, it stops updating TTL;
[0014] When the TTL of the target heartbeat key expires, Redis deletes the target heartbeat key;
[0015] When the first monitoring service process detects that the target heartbeat key does not exist, an abnormal logic process is performed on the first business process.
[0016] In a possible implementation, the first business process writes a target heartbeat key named with a unique identifier to Redis, including:
[0017] The first business process performs the following steps:
[0018] The identifier is obtained by concatenating a preset identifier as a prefix and a process name of the first business process as a suffix;
[0019] Read all key names prefixed with a preset identifier from Redis;
[0020] If the identifier does not exist in Redis, create and write a target heartbeat key named with the identifier to Redis;
[0021] Create a child process that periodically updates the TTL of the target heartbeat key.
[0022] In a possible implementation, the period of updating the TTL of the first service process is less than the TTL; periodically updating the TTL of the target heartbeat key includes:
[0023] Control the child process to periodically call the Redis EXPIRE command, or the EX option of the SET command, to set the TTL of the target heartbeat key.
[0024] In a possible implementation, the first monitoring service process monitors whether the target heartbeat key in Redis exists, including:
[0025] The first monitoring service process performs the following steps:
[0026] Fill a preset key name array with key names prefixed by a preset identifier, wherein the preset key name array at least includes the key name of the target heartbeat key;
[0027] Get all key names in Redis that are prefixed with a preset identifier and assign them to the key name array within the lifetime;
[0028] The array index is cleared to zero, and the array index points to the key name in the preset key name array;
[0029] Search the key name pointed to by the current array index of the preset key name array in the key name array within the lifetime;
[0030] If the search fails, the business process exception logic corresponding to the key name pointed to by the current array index is processed;
[0031] If found, the array index increases by 1;
[0032] When all array indexes in the preset key name array have been scanned, a detection cycle is delayed;
[0033] Get all key names in Redis that are prefixed with the preset identifier and repeat the above steps.
[0034] According to a second aspect of an embodiment of the present invention, a system for monitoring process status using a watchdog mechanism is provided, the system comprising at least one business process, at least one monitoring service process and Redis;
[0035] The first business process is used to write a target heartbeat key named with a unique identifier to Redis when initialized; and is also used to set a TTL for the target heartbeat key; wherein the first business process represents any one of the at least one business process;
[0036] Redis, used to store target heartbeat keys;
[0037] The first business process is also used to periodically update the TTL during runtime;
[0038] Redis is also used to receive the TTL updated by the first business process;
[0039] The first monitoring service process is used to monitor whether a target heartbeat key exists in Redis; wherein the first monitoring service process represents a process that monitors the first business process in at least one monitoring service process.
[0040] In a possible implementation, the first business process is further configured to stop updating the TTL when the operation ends;
[0041] Redis is also used to delete the target heartbeat key when its TTL expires;
[0042] The first monitoring service process is also used to perform abnormal logic processing on the first business process when it is detected that the target heartbeat key does not exist.
[0043] In a possible implementation, when the first service process is initialized, it is specifically used to:
[0044] The identifier is obtained by concatenating a preset identifier as a prefix and a process name of the first business process as a suffix;
[0045] Read all key names prefixed with a preset identifier from Redis;
[0046] If the identifier does not exist in Redis, create and write a target heartbeat key named with the identifier to Redis;
[0047] Create a child process that periodically updates the TTL of the target heartbeat key.
[0048] In a possible implementation, the period at which the first service process updates TTL is less than TTL; the first service process is specifically configured to:
[0049] During runtime, the control child process periodically calls the Redis EXPIRE command, or the EX option of the SET command, to set the TTL of the target heartbeat key.
[0050] In a possible implementation, each monitoring service process is specifically used to:
[0051] Fill a preset key name array with a key name prefixed by a preset identifier, wherein the preset key name array includes a heartbeat key name written into the Redis when each business process is initialized;
[0052] Get all key names in Redis that are prefixed with a preset identifier and assign them to the key name array within the lifetime;
[0053] The array index is cleared to zero, and the array index points to the key name in the preset key name array;
[0054] Search the key name pointed to by the current array index of the preset key name array in the key name array within the lifetime;
[0055] If the search fails, the business process corresponding to the key pointed to by the current array index will be processed with exception logic;
[0056] If found, the array index increases by 1;
[0057] When all array indexes in the preset key name array have been scanned, a detection cycle is delayed;
[0058] Get all key names in Redis that are prefixed with the preset identifier and repeat the above steps.
[0059] According to a third aspect of an embodiment of the present invention, a computer program product is provided, characterized in that when instructions in the computer program product are executed by a processor of an electronic device, the electronic device executes a method for monitoring a process status by using a watchdog mechanism as in the first aspect of the present invention or any possible implementation of the first aspect.
[0060] The embodiment of the present invention provides a method, system and computer program product for monitoring the process status by using a watchdog mechanism. The method uses Redis as the middleware for data interaction between multiple processes. Each business process creates a heartbeat key in Redis and regularly updates the TTL of the heartbeat key to achieve the purpose of feeding the watchdog. The management process continuously detects whether the heartbeat key of each business process exists. If the heartbeat key exists, it indicates that the business process corresponding to the key is running normally. If a heartbeat key does not exist, it indicates that the business process corresponding to the key has exited abnormally, thereby realizing the status monitoring of the business process corresponding to the heartbeat key. Since Redis is inherently characterized by high concurrency, when multiple business processes operate simultaneously, Redis ensures the consistency and accuracy of data, avoids the problems of data competition and deadlock in shared memory, and improves system stability. Moreover, Redis is used for the process interaction between multiple processes, supports rich data structures and has rich commands and application program interface interfaces, supports distributed deployment and expansion, supports persistence and backup, and these features enable developers to easily implement various functions. At the same time, the heartbeat key based on Redis can be flexibly expanded. Each process will create a heartbeat key when it is initialized, and the uninitialized process will not create a heartbeat key. Therefore, it has adaptive function for the increase or decrease of business processes. BRIEF DESCRIPTION OF THE DRAWINGS
[0061] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0062] Figure 1 A schematic diagram of a system for monitoring process status using a watchdog mechanism provided by an embodiment of the present invention;
[0063] Figure 2 A flowchart of a method for monitoring process status using a watchdog mechanism provided by an embodiment of the present invention;
[0064] Figure 3 A flow chart of a method for a business process to write a target heartbeat key to Redis provided by an embodiment of the present invention;
[0065] Figure 4 A flow chart of a method for updating the TTL of a target heartbeat key provided by an embodiment of the present invention;
[0066] Figure 5 A flowchart of a method for monitoring a target heartbeat key by a monitoring service provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0067] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0068] For ease of understanding, the terms involved in the embodiments of the present invention are explained below:
[0069] Watchdog mechanism: a hardware or software mechanism designed to monitor and handle system failures to ensure stable system operation. Its working principle is as follows:
[0070] 1. Monitoring tasks: The watchdog will periodically (usually a few seconds or minutes) detect the normal operation of the system. It can monitor various system states, such as CPU load, system memory, hard disk activity, network connection, etc.
[0071] 2. Heartbeat signal: The application or operating system will periodically send heartbeat signals to the watchdog to prove that they are still running normally. If a heartbeat signal is successfully received, the watchdog will consider the system normal. Otherwise, it will start the corresponding processing mechanism.
[0072] 3. Monitoring timeout: If the watchdog does not receive a heartbeat signal within a certain period of time, it will be considered that the system has failed or crashed. It can perform a series of predefined operations, such as restarting the system, alarming, recording error logs, etc.
[0073] 4. System recovery: Once the watchdog triggers the fault handling mechanism, it will try to restore the system to normal operation. This may include restarting the system, reloading the operating system, shutting down failed processes, or taking other necessary measures.
[0074] Redis: is an open source, memory-based, key-value pair storage database that can be used as a database, cache, and message middleware. In the key-value pairs stored in Redis, the key has an expiration time attribute. The TTL of the key can be determined by setting the expiration time, or it can be left unset to make it exist permanently. If a key is set with an expiration time, Redis will automatically delete the key when it expires (TTL has ended). The main features of Redis are:
[0075] 1. Based on memory storage: All Redis data is stored in memory, which makes it have extremely high read and write speeds. At the same time, Redis also supports persisting data in memory to disk to ensure data reliability.
[0076] 2. Rich data types: Redis supports multiple data types, each of which has a dedicated command to operate, which provides great flexibility for developers.
[0077] 3. Atomic operation: All Redis operations are atomic, which means that when multiple clients operate simultaneously, Redis guarantees data consistency and accuracy.
[0078] 4. Rich features: Redis provides rich features, such as publish / subscribe mode, transactions, Lua scripts, persistence, clustering, etc., which can meet the needs of different scenarios.
[0079] 5. High performance: Redis is designed to have extremely high performance, can handle thousands of concurrent connections, and can perform millions of operations per second.
[0080] EXPIRE command: used to set the expiration time of a key in seconds. The EXPIRE command is a command used in Redis to set the TTL of a key, which allows the key to be automatically removed after a specified number of seconds. This command provides an automatic key expiration function, avoiding the need to manually perform deletion operations within a specified time.
[0081] EX option of SET command: allows to specify the TTL of a key while setting a key-value pair. In Redis, the EX option of SET command provides a convenient way to set the value of a key and the TTL of the key at the same time. This expiration time is in seconds, which means that the key-value pair will be automatically deleted after the specified number of seconds.
[0082] The embodiment of the present invention provides a system for monitoring process status using a watchdog mechanism, such as Figure 1 As shown, the system includes at least one business process (eg, business process A, business process B, and business process C), at least one monitoring service process, and Redis. The system runs in an embedded computing system.
[0083] An embodiment of the present invention also provides a method for monitoring process status using a watchdog mechanism, which is applied to the above-mentioned system for monitoring process status using a watchdog mechanism. The method is executed by an electronic device or a functional module or functional entity in the electronic device that can implement the method.
[0084] like Figure 2 As shown, the method may include the following steps:
[0085] S210, when the first business process is initialized, writes a target heartbeat key named with a unique identifier to Redis, and sets a TTL for the target heartbeat key.
[0086] Each initialized business process writes a heartbeat key named with a unique identifier to Redis and sets a TTL for the heartbeat key. An uninitialized business process does not write a heartbeat key to Redis, thus achieving the function of adaptive increase and decrease of the heartbeat key in Redis.
[0087] To avoid key conflicts, the heartbeat key name of each business process is different and unique. In addition, the TTL setting can be adjusted according to specific application scenarios and requirements, and can also be set considering the impact of network delay and jitter.
[0088] The first business process in the initialized business processes corresponds to the target heartbeat key. When the first business process is initialized, it writes the target heartbeat key named with the unique identifier to Redis and sets the TTL of the target heartbeat key.
[0089] S220, Redis stores the target heartbeat key.
[0090] Redis stores and manages heartbeat keys, which include target heartbeat keys.
[0091] S230: When the first service process is running, the TTL of the target heartbeat key is periodically updated.
[0092] When the first service process is running, in order to prevent the TTL of the target heartbeat key from expiring, the TTL is periodically updated.
[0093] In the watchdog mechanism, updating the TTL of the target heartbeat key is a dog feeding operation. The first business process periodically feeds the dog, and the watchdog continuously monitors the first business process.
[0094] S240, Redis receives the TTL updated by the first business process for the target heartbeat key.
[0095] Redis receives the update of the TTL of the target heartbeat key by the first business process.
[0096] S250, the first monitoring service process monitors whether the target heartbeat key exists in Redis.
[0097] The first monitoring service process in the monitoring service process periodically detects whether a target heartbeat key in Redis exists; wherein the first monitoring service process represents a process in a monitoring service process that monitors the first business process.
[0098] When the first business process is running, TTL is set periodically. If TTL does not expire, Redis will not delete it, and the first monitoring service process can continue to detect the existence of the target heartbeat key in Redis.
[0099] In the watchdog mechanism, the monitoring service process is the watchdog.
[0100] S260: When the first service process ends its operation, it stops updating TTL.
[0101] When the first business process ends, the TTL is stopped from being updated.
[0102] In the watchdog mechanism, this step is to stop feeding the dog.
[0103] S270: When the TTL of the target heartbeat key expires, Redis deletes the target heartbeat key.
[0104] S280: When the first monitoring service process detects that the target heartbeat key does not exist, the first business process is subjected to abnormal logic processing.
[0105] The first monitoring service process periodically detects the heartbeat key in Redis. If the heartbeat key that existed in the previous cycle does not exist in the current cycle, the first monitoring service process will trigger the abnormal logic.
[0106] If a key is automatically deleted due to TTL expiration, it means that the corresponding business process has not sent heartbeats for a long time and may have crashed or become unresponsive. The monitoring service process will trigger abnormal logic, including restarting the first business process and / or sending an alarm notification to the administrator, or performing other predetermined operations.
[0107] In the watchdog mechanism, this step is that the watchdog times out and is not fed, triggering the fault handling mechanism.
[0108] The embodiment of the present invention provides a system for monitoring the process status by using a watchdog mechanism, and a method for monitoring the process status by using a watchdog mechanism applied to the system. The method uses Redis as the middleware for data interaction between multiple processes. Each business process creates a heartbeat key in Redis and regularly updates the TTL of the heartbeat key to achieve the purpose of feeding the dog. The monitoring service process detects whether the heartbeat key of each business process exists. If the heartbeat key exists, it indicates that the business process corresponding to the key is running normally. If a heartbeat key does not exist, it indicates that the business process corresponding to the key has exited abnormally, thereby realizing the status monitoring of the business process corresponding to the heartbeat key. Since Redis is inherently characterized by high concurrency, when multiple business processes are operated simultaneously, Redis ensures the consistency and accuracy of data, avoids the problems of data competition and deadlock in shared memory, and improves the stability of the system. Moreover, Redis is used for the process interaction between multiple processes, supports rich data structures and has rich commands and application program interface interfaces, supports distributed deployment and expansion, supports persistence and backup, and these features enable developers to conveniently implement various functions. At the same time, the heartbeat key based on Redis can be flexibly expanded. Each process will create a heartbeat key when it is initialized, and the uninitialized process will not create a heartbeat key. Therefore, it has adaptive function for the increase or decrease of business processes.
[0109] Embodiment 2
[0110] In some embodiments, Figure 3 As shown, step S210: when the first business process is initialized, writes a target heartbeat key named with a unique identifier to Redis and sets a TTL for the target heartbeat key, which may include the following steps:
[0111] S211: Use a preset identifier as a prefix and a process name of the first business process as a suffix to obtain an identifier.
[0112] In one example, the preset identifier is: watchdog.
[0113] S212, read all key names prefixed with a preset identifier from Redis;
[0114] S213: If the identifier does not exist in Redis, create and write a target heartbeat key named with the identifier to Redis.
[0115] S214, creating a subprocess for periodically updating the TTL of the target heartbeat key.
[0116] The TTL update period is smaller than the TTL to ensure that the target heartbeat key does not expire when the first service process is running.
[0117] In one example, the TTL of the target heartbeat key is 30 seconds, and the business process updates the TTL value of the heartbeat key every 10 seconds.
[0118] Step S230: When the first service process is running, periodically updating the TTL of the target heartbeat key may include the following steps:
[0119] Control the child process to periodically call the Redis EXPIRE command, or the EX option of the SET command, to set the TTL of the target heartbeat key.
[0120] like Figure 4 As shown, the first business process controls the subprocess, and sets the TTL of the target heartbeat key once every time a TTL update cycle is delayed until the first business process ends.
[0121] The method provided by the embodiment of the present invention periodically updates the TTL of the jump key in Redis to indicate the normal operation status of the business process for detection and judgment by the monitoring service process.
[0122] Embodiment 3
[0123] In some embodiments, the method of monitoring the process status of the monitoring service process using the watchdog mechanism includes: Figure 5 Steps shown:
[0124] S510: Fill a preset key name array with key names prefixed by a preset identifier.
[0125] The key name prefixed with the preset identifier is the heartbeat key name. The heartbeat key name is prefixed with the preset identifier and the business process name is suffixed.
[0126] Create a preset key name array in advance. When initializing the preset key name array, fill the preset key name array with the heartbeat key name written to Redis when each business process is initialized. When the business process writes a new heartbeat key name to Redis, the new heartbeat key name is filled into the preset key name array.
[0127] For the first monitoring service process that detects the first business process, the preset key name array includes at least a target heartbeat key name.
[0128] S520, obtain all key names prefixed with a preset identifier in Redis, and assign them to the key name array within the lifetime.
[0129] Since Redis will automatically delete the key name when it expires (TTL has ended), the key names in Redis are all key names within their life cycle. The key names prefixed with the preset identifier among these key names are assigned to the key name array within the life cycle. Then the key name array within the life cycle includes all the key names in Redis that are prefixed with the preset identifier.
[0130] Let's start periodically checking the key names in Redis.
[0131] S530, array index is cleared.
[0132] The array index at which to start scanning the preset key array, where each array index points to a key in the preset key array.
[0133] S540, searching the key name pointed to by the current array index of the preset key name array in the key name array within the lifetime.
[0134] S540: If the search fails, an exception logic process is performed on the business process corresponding to the key name pointed to by the current array index.
[0135] S550, if found, the array index increases by 1.
[0136] If found, the array index increases by 1, which means scanning to the next array index.
[0137] S560, when all array indexes in the preset key name array are scanned, delay a detection cycle.
[0138] The detection period is smaller than the minimum TTL of the key name to ensure that the heartbeat key can be found when each business process is running.
[0139] In an example, the TTL of a key name is the smallest, which is 30 seconds, and the monitoring service process checks it every 20 seconds.
[0140] S520 to S560 are repeatedly executed.
[0141] In the method provided by the embodiment of the present invention, the monitoring service process periodically detects the key name prefixed with a preset identifier in Redis to achieve status monitoring of the business process corresponding to the key name.
[0142] Embodiment 4
[0143] An embodiment of the present invention provides a computer program product, which includes computer program instructions. When the instructions in the computer program product are executed by a processor of an electronic device, the electronic device executes the steps of the method of using a watchdog mechanism to monitor the process status of various embodiments of the present invention described above in this specification.
[0144] The computer program product may be written in any combination of one or more programming languages to write program code for performing the operations of the embodiments of the present invention, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server.
[0145] For the above-mentioned method embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should know that the present invention is not limited by the order of the actions described, because according to the present invention, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present invention.
[0146] It should be noted that the various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0147] The steps in the methods of the embodiments of the present invention may be adjusted in order, combined, or deleted according to actual needs, and the technical features recorded in the embodiments may be replaced or combined.
[0148] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0149] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly by hardware, software units executed by a processor, or a combination of the two. The software units may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0150] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0151] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for monitoring process status using a watchdog mechanism, characterized in that: Applicable to a system that uses a watchdog mechanism to monitor process status, the system includes at least one business process, at least one monitoring service process and Redis; the method includes: When the first business process is initialized, the first business process writes a target heartbeat key named with a unique identifier to Redis, and sets a TTL for the target heartbeat key; wherein the first business process represents any one of the at least one business process; The Redis stores the target heartbeat key; When the first service process is running, periodically updating the TTL; The Redis receives the TTL updated by the first business process; The first monitoring service process monitors whether the target heartbeat key in the Redis exists; wherein the first monitoring service process represents a process in the at least one monitoring service process that monitors the first business process.
2. The method according to claim 1, characterized in that The method further comprises: When the first service process ends its operation, the updating of the TTL is stopped; When the TTL of the target heartbeat key expires, Redis deletes the target heartbeat key; When the first monitoring service process detects that the target heartbeat key does not exist, it performs abnormal logic processing on the first business process.
3. The method according to claim 1 or 2, characterized in that: The first business process writes a target heartbeat key named with a unique identifier to Redis, including: The first business process performs the following steps: Using a preset identifier as a prefix and the process name of the first business process as a suffix to obtain an identifier; Read all key names prefixed with the preset identifier from the Redis; If the identifier does not exist in the Redis, create and write a target heartbeat key named with the identifier to Redis; A subprocess is created for periodically updating the TTL of the target heartbeat key.
4. The method according to claim 3, characterized in that The period of updating the TTL by the first business process is less than the TTL; and the periodic updating of the TTL of the target heartbeat key includes: The subprocess is controlled to periodically call the Redis EXPIRE command, or the EX option of the SET command, to set the TTL of the target heartbeat key.
5. The method according to claim 1, characterized in that The first monitoring service process monitors whether the target heartbeat key in the Redis exists, including: The first monitoring service process performs the following steps: Fill a preset key name array with key names prefixed by a preset identifier, wherein the preset key name array includes at least the key name of the target heartbeat key; Get all key names in Redis that are prefixed with a preset identifier and assign them to the key name array within the lifetime; The array index is cleared to zero, and the array index points to the key name in the preset key name array; Search the key name pointed to by the current array index of the preset key name array in the key name array within the lifetime; If the search fails, the business process exception logic corresponding to the key name pointed to by the current array index is processed; If found, the array index increases by 1; When all array indexes in the preset key name array have been scanned, a detection cycle is delayed; Get all key names in Redis that are prefixed with the preset identifier and repeat the above steps.
6. A system for monitoring process status using a watchdog mechanism, characterized in that: The system includes at least one business process, at least one monitoring service process and Redis; A first business process is used to write a target heartbeat key named with a unique identifier to the Redis when initialized; and is also used to set a TTL for the target heartbeat key; wherein the first business process represents any one of the at least one business process; The Redis is used to store the target heartbeat key; The first business process is further configured to periodically update the TTL during operation; The Redis is further used to receive the TTL updated by the first business process; The first monitoring service process is used to monitor whether the target heartbeat key in the Redis exists; wherein the first monitoring service process represents a process in the at least one monitoring service process used to monitor the first business process.
7. The system according to claim 6, characterized in that The first business process is further used to stop updating the TTL when the operation ends; The Redis is further used to delete the target heartbeat key when the TTL of the target heartbeat key expires; The first monitoring service process is further used to perform abnormal logic processing on the first business process when it is detected that the target heartbeat key does not exist.
8. The system according to claim 6 or 7, characterized in that: When the first service process is initialized, it is specifically used to: Using a preset identifier as a prefix and the process name of the first business process as a suffix to obtain an identifier; Read all key names prefixed with the preset identifier from the Redis; If the identifier does not exist in the Redis, create and write a target heartbeat key named with the identifier to Redis; A subprocess is created for periodically updating the TTL of the target heartbeat key.
9. The system according to claim 8, characterized in that The period during which the first service process updates the TTL is less than the TTL; the first service process is specifically used to: During operation, the subprocess is controlled to periodically call the Redis EXPIRE command or the EX option of the SET command to set the TTL of the target heartbeat key.
10. The system according to claim 6, characterized in that Each monitoring service process is specifically used for: Fill a preset key name array with key names prefixed by a preset identifier, wherein the preset key name array includes key names written into the Redis when each business process is initialized; Get all key names in Redis that are prefixed with a preset identifier and assign them to the key name array within the lifetime; The array index is cleared to zero, and the array index points to the key name in the preset key name array; Search the key name pointed to by the current array index of the preset key name array in the key name array within the lifetime; If the search fails, the business process corresponding to the key pointed to by the current array index will be processed with exception logic; If found, the array index increases by 1; When all array indexes in the preset key name array have been scanned, a detection cycle is delayed; Get all key names in Redis that are prefixed with the preset identifier and repeat the above steps.
11. A computer program product, characterized in that When the instructions in the computer program product are executed by a processor of an electronic device, the electronic device executes the method for monitoring process status using a watchdog mechanism as described in any one of claims 1 to 5.