CN102495793B - Method for detecting endless loop task - Google Patents
Method for detecting endless loop task Download PDFInfo
- Publication number
- CN102495793B CN102495793B CN201110356415.9A CN201110356415A CN102495793B CN 102495793 B CN102495793 B CN 102495793B CN 201110356415 A CN201110356415 A CN 201110356415A CN 102495793 B CN102495793 B CN 102495793B
- Authority
- CN
- China
- Prior art keywords
- task
- endless loop
- priority
- operating system
- list
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Landscapes
- Debugging And Monitoring (AREA)
Abstract
The invention provides a method for detecting an endless loop task. The method comprises the following steps: an endless loop monitoring task with highest priority and an endless loop detecting task with the lowest priority are generated and enabled to operate periodically; everytime when the endless loop detecting task operates, the present time is recorded; everytime when the endless loop monitoring task operates, whether an endless loop task exists in an operating system is judged according to the operating condition of the endless loop detecting task; and the endless loop task existing in the system is located, and the located endless loop task is processed. The method provided by the invention can detect the endless loop task in the system under the premise of lower CPU resource consumption, and is simple to implement.
Description
Technical field
The present invention relates to computer operating system technical field, particularly a kind of method that detects endless loop task.
Background technology
In computer operating system, detection and the processing thereof of relevant endless loop are very important technology.
Application number is in 01112526.8 application for a patent for invention, to disclose a kind of disposal route of endless loop under real-time multitask, it has described a kind of in real-time multi-task operating system, and a kind of monitoring and the disposal route of class endless loop or endless loop appears in task abnormity operation.The basic thought of this patent is to use clock interrupt service routine (ISR) and task to switch the working time that Hook Function carrys out monitor task, if be greater than certain threshold values the working time of task, think that endless loop has appearred in this task, the method will consume cpu resource in a large number.Interrupting and task is switched and linked up with the method that function detects endless loop and all have identical shortcoming with system clock similarly.
Summary of the invention
The invention provides a kind of method that detects endless loop task in multiple task operating system, while detecting endless loop or class endless loop task to overcome prior art to the too much problem of operating system cpu resource consumption, it is few that the inventive method consumes cpu resource, and realize simple.
The application discloses a kind of method that detects endless loop task, and the operating system that is applicable to based on priority, task be dispatched, comprising:
A, generation have the endless loop monitor task of limit priority and have the endless loop Detection task of lowest priority, endless loop monitor task and the cycling service of endless loop Detection task;
When B, endless loop Detection task each run, record current time;
When C, endless loop monitor task each run, according to whether having endless loop task in the ruuning situation decision operation system of endless loop Detection task, while there is endless loop task in decision-making system, endless loop task is positioned, and the endless loop task navigating to is processed;
Described endless loop task positioned and comprised:
D, judge whether to arrange endless loop sign, if do not arrange, carry out E, otherwise, jump to H;
E, a task list is set for each priority, and for each task list arranges a priority controll block, task run field being set in the task control block (TCB) of each task, its value is set to 0, to operating system registered task, switch Hook Function, and endless loop sign is set; Wherein, comprise all tasks with respective priority in operating system in each task list, in each priority controll block, comprise task run field, its value is set to 0; When task switching Hook Function is called, the task run field of the task control block (TCB) of the task that this is scheduled adds 1 operation, and the task run field in the priority controll block of the task list under this task is added to 1 operation;
F, endless loop monitor task are sold CPU, enter sleep state;
G, when the sleep cycle of endless loop monitor task expires while being waken up, endless loop monitor task is dispatched again, returns to C;
H, from priority controll block corresponding to lowest priority, start to detect, for the non-zero priority of operation field in priority controll block, the task control block (TCB) that continues to detect task list corresponding to this priority, the task that the task run field of task control block (TCB) is non-zero is defined as endless loop task.
Preferably, in described C according to whether existing endless loop task to be in the ruuning situation decision operation system of endless loop Detection task:
During according to current time and the operation of endless loop Detection task, the current time of record, calculates the time interval that endless loop Detection task does not obtain scheduling, if the described time interval surpasses the threshold value setting in advance, in decision system, has endless loop task.
Preferably, while there is not endless loop task in described C in decision-making system, jump to F.
Preferably, after being processed, endless loop task further comprises: nullify registered task and switch Hook Function, destroy set task list, and remove endless loop sign, return to F.
Preferably, described the endless loop task navigating to is processed and comprised: hang up endless loop task.
Preferably, after hanging up endless loop task, further comprise: the endless loop task of hanging up is debugged to the code position that location endless loop occurs, and recording-related information.
Preferably, in described E, for arranging a task list, each priority comprises: by operating system interface, obtain the task control block (TCB) list that comprises all tasks in operating system, all tasks are divided according to priority, obtain the task list corresponding to each priority.
Preferably, the sleep cycle of described endless loop monitor task is longer than the sleep cycle of described endless loop Detection task.
As seen from the above technical solution, first the endless loop monitor task by cycling service and endless loop Detection task determine in operating system, whether there is endless loop task in the present invention; When there is endless loop task, by dividing the task list based on priority, the priority controll block of task list is set, and registered task switches Hook Function the respective field in the controll block of the task of being scheduled and priority controll block thereof is arranged, thereby realize, endless loop task is positioned.
For avoiding consuming excess CPU resources, the present invention does not use system clock interrupt service routine to detect endless loop, but only by expending the endless loop monitor task of the cycling service that cpu resource is extremely low and endless loop Detection task, exist after endless loop in operating system being detected, just to operating system registered task, switching Hook Function positions endless loop task, and, the operation that task is switched in Hook Function is very simple, extremely low to the consumption of cpu resource, therefore, it is few that the technical scheme that the present invention proposes has the cpu resource of consumption, and realize simple beneficial effect.
Accompanying drawing explanation
Fig. 1 is the schematic flow sheet of the method for the better detection endless loop task of the present invention one;
Fig. 2 is the operational scheme schematic diagram of endless loop monitor task of the present invention;
Fig. 3 is the operational scheme schematic diagram of endless loop Detection task of the present invention;
Fig. 4 the present invention is based on the schematic diagram that priority is divided task list.
Embodiment
For making object of the present invention, technical scheme and advantage clearer, referring to the accompanying drawing embodiment that develops simultaneously, the present invention is described in further detail.
The present invention utilizes in the preemptive priority formula operating system of non-round-robin, as long as high-priority task is not blocked or is not initiatively sold CPU, low priority task or just can not obtain the principle of scheduling with other task that this high-priority task has an equal priority, proposes a kind of method that detects endless loop task so.First the method generates the endless loop monitor task with limit priority and the endless loop Detection task with lowest priority, then make endless loop monitor task and the cycling service of endless loop Detection task, during endless loop Detection task each run, record current time, during endless loop monitor task each run, according to whether having endless loop task in the ruuning situation decision operation system of endless loop Detection task, while there is endless loop task in decision-making system, endless loop task is positioned, and the endless loop task navigating to is processed.
The present invention is applicable to all operating system of task being dispatched based on priority, is specially adapted to vxWorks real-time multi-task operating system.
Below by a preferred embodiment, the present invention is described in detail.
Fig. 1 is the schematic flow sheet of the method for the better detection endless loop task of the present invention one.Referring to Fig. 1, the method comprises:
Step 101: generate the endless loop monitor task with limit priority and endless loop Detection task, endless loop monitor task and the cycling service of endless loop Detection task with lowest priority.
The priority of supposing task in operating system is 0~100, and priority 0 is lowest priority, and priority 1 00 is limit priority, and the priority of the circularly monitoring task of can checkmating is set to 100, and the priority of the cycle detection of checkmating task is set to 0.
For guaranteeing that endless loop monitor task and endless loop Detection task do not take a large amount of CPU, in the present invention, endless loop monitor task and endless loop Detection task be periodically operation all, that is: in the cycle to fix, every sleep a period of time operation once.Wherein, the every sleep longer cycle of endless loop monitor task moves once, as shown in Figure 2; The every sleep of endless loop Detection task moved once compared with the short period, as shown in Figure 3.Here, can sleep cycle be set according to actual conditions.
Step 102: endless loop monitor task, according to whether having endless loop in the ruuning situation decision operation system of endless loop Detection task, if there is endless loop, performs step 103, otherwise, jump to step 107.
During endless loop Detection task each run, record the current time of this operation, during endless loop monitor task each run, the current time of record during according to current time and the operation of endless loop Detection task, calculating endless loop Detection task has and how long has not moved, and endless loop Detection task does not obtain the time interval of scheduling.Because the priority of endless loop Detection task in operating system is minimum, if there is not endless loop task in operating system, so, endless loop Detection task will likely be dispatched in the situation that other tasks are finished dealing with, that is: can within the rationally long time interval, once be dispatched, otherwise, long if endless loop Detection task does not obtain the time interval of scheduling, surpassed the threshold values setting in advance, showing has task to occur endless loop or class endless loop in operating system.
Step 103: judge whether to arrange endless loop sign, if do not arrange, execution step 104; If arrange, jump to step 109.
Step 104: for each priority arranges a task list, and for each task list arranges a priority controll block, task run field is set in the task control block (TCB) of each task, its value is set to 0; Wherein, in each task list, comprise all tasks with respective priority in operating system, in each priority controll block, comprise a task digital section and task run field, a task digital section is filled total number of the task of respective priority, and task run field is set to 0.
In this step, can obtain the task control block (TCB) list that comprises all tasks in operating system by operating system interface, and all tasks are divided according to priority, thereby obtain a plurality of task lists based on priority, as shown in Figure 4.
Wherein, the task run field in task control block (TCB) can obtain in the user's reserved field expansion in task control block (TCB).
Step 105: switch Hook Function to operating system registered task.
In operating system, every generation one subtask is switched, and will call once registered task and switch Hook Function.In the present invention, task is switched Hook Function by priority index priority controll block, when task switching Hook Function is called, it carries out following operation: the operation field in the task control block (TCB) of the task that this is scheduled adds 1 operation, and the task run field in the priority controll block of the task list under this task is added to 1 operation.
Step 106: endless loop sign is set.
Here, in fact endless loop sign for the performed step 104 of endless loop monitor task and step 105 are carried out to mark, is provided with endless loop sign, shows endless loop monitor task executed step 104 and step 105, its role is to save cpu resource.
The execution sequence of above-mentioned steps 104~106 can be changed arbitrarily.
Step 107: endless loop monitor task is sold CPU, enters sleep state, other tasks in operating system are dispatched.
In the preemptive priority formula operating system at non-round-robin, as long as high priority task does not block or does not initiatively sell CPU, low priority task or just can not be dispatched with other task that this high-priority task has an equal priority so, and while only there is endless loop task in operating system in endless loop monitor task of the present invention, just can be to providing registered task to switch Hook Function, therefore, if registered task is switched Hook Function, so, after endless loop monitor task is sold CPU, in operating system, only have priority just can be dispatched higher than task and the endless loop task of endless loop task priority, for the task of obtaining scheduling, task is switched Hook Function the operation field in its task control block (TCB) is added to 1 operation, and the task run field in its corresponding priority controll block is added to 1 operation, so, according to the task control block (TCB) operation value of field and the value of priority controll block task run field, endless loop task will be located.If do not have registered task to switch Hook Function, show not exist in current operation system endless loop task, the object that endless loop monitor task is sold CPU is only to make the task of other priority to be dispatched, and not for endless loop task is positioned.
Step 108: when the sleep cycle of endless loop monitor task expires while being waken up, endless loop monitor task is dispatched again, returns to step 102.
Step 109: determine endless loop task, particularly: from priority controll block corresponding to lowest priority, start to detect, if the operation field in priority controll block is non-zero, there is endless loop in the task of showing respective priority, then detect the task control block (TCB) of task list corresponding to this priority, if it is non-zero the task run field of task control block (TCB) of certain task to be detected, show that endless loop has appearred in this task.
Step 110: endless loop task is processed.
Detect after endless loop task, can hang up endless loop task or class endless loop task, and use operating system instrument to debug and record there is the task of endless loop, and, this task stack of standard interface Functional Analysis that can utilize operating system to provide, the code position that accurately location endless loop occurs, and user's interface recording-related information.
Step 111: releasing resource, specifically comprises: nullify chartered task and switch Hook Function, destroy set task list, and remove endless loop sign, return to step 107.
So far, finish this preferred approach flow process.
As seen from the above-described embodiment, first the endless loop monitor task by cycling service and endless loop Detection task determine in operating system, whether there is endless loop task in the present invention; When there is endless loop task, by dividing the task list based on priority, the priority controll block of task list is set, and registered task switches Hook Function the respective field in the controll block of the task of being scheduled and priority controll block thereof is arranged, thereby realize, endless loop task is positioned.
For avoiding consuming excess CPU resources, the present invention does not use system clock interrupt service routine to detect endless loop, but only by expending the endless loop monitor task of the cycling service that cpu resource is extremely low and endless loop Detection task, exist after endless loop in operating system being detected, just to operating system registered task, switching Hook Function positions endless loop task, and, the operation that task is switched in Hook Function is very simple, extremely low to the consumption of cpu resource, therefore, it is few that the technical scheme that the present invention proposes has the cpu resource of consumption, and realize simple beneficial effect.
The foregoing is only preferred embodiment of the present invention, in order to limit the present invention, within the spirit and principles in the present invention not all, any modification of making, be equal to replacement, improvement etc., within all should being included in the scope of protection of the invention.
Claims (7)
1. detect a method for endless loop task, the operating system that is applicable to based on priority, task be dispatched, is characterized in that:
A, generation have the endless loop monitor task of limit priority and have the endless loop Detection task of lowest priority, endless loop monitor task and the cycling service of endless loop Detection task;
When B, endless loop Detection task each run, record current time;
When C, endless loop monitor task each run, according to whether having endless loop task in the ruuning situation decision operation system of endless loop Detection task, while there is endless loop task in decision-making system, endless loop task is positioned, and the endless loop task navigating to is processed;
Described endless loop task positioned and comprised:
D, judge whether to arrange endless loop sign, if do not arrange, carry out E, otherwise, jump to H;
E, a task list is set for each priority, and for each task list arranges a priority controll block, task run field being set in the task control block (TCB) of each task, its value is set to 0, to operating system registered task, switch Hook Function, and endless loop sign is set; Wherein, comprise all tasks with respective priority in operating system in each task list, in each priority controll block, comprise task run field, its value is set to 0; When task switching Hook Function is called, the task run field of the task control block (TCB) of the task that this is scheduled adds 1 operation, and the task run field in the priority controll block of the task list under this task is added to 1 operation;
F, endless loop monitor task are sold CPU, enter sleep state;
G, when the sleep cycle of endless loop monitor task expires while being waken up, endless loop monitor task is dispatched again, returns to C;
H, from priority controll block corresponding to lowest priority, start to detect, for the non-zero priority of operation field in priority controll block, the task control block (TCB) that continues to detect task list corresponding to this priority, the task that the task run field of task control block (TCB) is non-zero is defined as endless loop task;
Wherein, in described C according to whether existing endless loop task to be in the ruuning situation decision operation system of endless loop Detection task:
During according to current time and the operation of endless loop Detection task, the current time of record, calculates the time interval that endless loop Detection task does not obtain scheduling, if the described time interval surpasses the threshold value setting in advance, in decision system, has endless loop task.
2. method according to claim 1, is characterized in that:
While there is not endless loop task in described C in decision-making system, jump to F.
3. method according to claim 1, is characterized in that, after endless loop task is processed, further comprises:
Nullify registered task and switch Hook Function, destroy set task list, and remove endless loop sign, return to F.
4. method according to claim 1, is characterized in that, described the endless loop task navigating to is processed and comprised: hang up endless loop task.
5. method according to claim 4, is characterized in that, after hanging up endless loop task, further comprises:
The endless loop task of hanging up is debugged to the code position that location endless loop occurs, and recording-related information.
6. method according to claim 1, is characterized in that, in described E, for each priority arranges a task list, comprises:
By operating system interface, obtain the task control block (TCB) list that comprises all tasks in operating system, all tasks are divided according to priority, obtain the task list corresponding to each priority.
7. method according to claim 1, is characterized in that,
The sleep cycle of described endless loop monitor task is longer than the sleep cycle of described endless loop Detection task.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201110356415.9A CN102495793B (en) | 2011-11-11 | 2011-11-11 | Method for detecting endless loop task |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201110356415.9A CN102495793B (en) | 2011-11-11 | 2011-11-11 | Method for detecting endless loop task |
Publications (2)
Publication Number | Publication Date |
---|---|
CN102495793A CN102495793A (en) | 2012-06-13 |
CN102495793B true CN102495793B (en) | 2014-11-05 |
Family
ID=46187618
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201110356415.9A Active CN102495793B (en) | 2011-11-11 | 2011-11-11 | Method for detecting endless loop task |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN102495793B (en) |
Families Citing this family (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105427695B (en) * | 2015-11-03 | 2018-11-02 | 中国农业大学 | Program class examination paper automatic assessment method and system |
CN110750450B (en) * | 2019-09-19 | 2022-08-16 | 深圳震有科技股份有限公司 | Method, device and system for positioning software endless loop and storage medium |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US5450586A (en) * | 1991-08-14 | 1995-09-12 | Hewlett-Packard Company | System for analyzing and debugging embedded software through dynamic and interactive use of code markers |
CN1811730A (en) * | 2006-02-22 | 2006-08-02 | 迈普(四川)通信技术有限公司 | Method for testing closed loop or similar closed loop task |
CN101853191A (en) * | 2010-06-23 | 2010-10-06 | 迈普通信技术股份有限公司 | Method for detecting task endless loop in operating system and operating system |
-
2011
- 2011-11-11 CN CN201110356415.9A patent/CN102495793B/en active Active
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US5450586A (en) * | 1991-08-14 | 1995-09-12 | Hewlett-Packard Company | System for analyzing and debugging embedded software through dynamic and interactive use of code markers |
CN1811730A (en) * | 2006-02-22 | 2006-08-02 | 迈普(四川)通信技术有限公司 | Method for testing closed loop or similar closed loop task |
CN101853191A (en) * | 2010-06-23 | 2010-10-06 | 迈普通信技术股份有限公司 | Method for detecting task endless loop in operating system and operating system |
Also Published As
Publication number | Publication date |
---|---|
CN102495793A (en) | 2012-06-13 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
JP5888629B2 (en) | Method, apparatus and system for scheduling processor cores in a multiprocessor core system | |
JP2013526754A5 (en) | ||
CN106326066B (en) | A kind of method and its system of the monitoring adjustment of tasks of embedded system response performance | |
CN101853191B (en) | Method for detecting task endless loop in operating system and operating system | |
CN102043667A (en) | Task scheduling method for embedded operating system | |
CN103294534B (en) | Task management system and method of distributed system | |
CN101561778B (en) | Method for detecting task closed loop of multi-task operating system | |
CN103164332B (en) | The detection of endless loop task and disposal route | |
EP3191917A1 (en) | Heuristic processsor power management in operating systems | |
CN102622300B (en) | Infinite loop or similar infinite loop detection method in multitask system | |
CN101751335B (en) | Method, device and cluster system for collecting rubbish of scheduling virtual machine | |
CN100543686C (en) | A kind of method and system that detect task closed loop | |
CN102495793B (en) | Method for detecting endless loop task | |
CN100394399C (en) | Method for testing closed loop or similar closed loop task | |
KR101203099B1 (en) | Method for monitoring running time of OS task framework and apparatus thereof | |
KR20090120970A (en) | A method of interrupt scheduling | |
CN101504615A (en) | Method and apparatus for providing positioning information for task endless loop | |
CN102799261B (en) | A kind of method and device realizing screen protection | |
CN110794759B (en) | PLC task scheduling method and device | |
CN100557576C (en) | The method and apparatus that operating system failure detects | |
EP2159692A1 (en) | Information processor and load arbitration control method | |
JP2005215816A (en) | Performance profiling method using hardware monitor | |
KR101725408B1 (en) | Tasks scheduling method for realtime operating system | |
US20120124582A1 (en) | Calculating Processor Load | |
KR101271854B1 (en) | Apparatus and method for scheduling task period |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
C14 | Grant of patent or utility model | ||
GR01 | Patent grant |