CN103164332A - Detection and processing method of endless loop task - Google Patents

Detection and processing method of endless loop task Download PDF

Info

Publication number
CN103164332A
CN103164332A CN2011104228511A CN201110422851A CN103164332A CN 103164332 A CN103164332 A CN 103164332A CN 2011104228511 A CN2011104228511 A CN 2011104228511A CN 201110422851 A CN201110422851 A CN 201110422851A CN 103164332 A CN103164332 A CN 103164332A
Authority
CN
China
Prior art keywords
task
endless loop
detection
control block
time
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.)
Granted
Application number
CN2011104228511A
Other languages
Chinese (zh)
Other versions
CN103164332B (en
Inventor
何三波
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Maipu Communication Technology Co Ltd
Original Assignee
Maipu Communication Technology Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Maipu Communication Technology Co Ltd filed Critical Maipu Communication Technology Co Ltd
Priority to CN201110422851.1A priority Critical patent/CN103164332B/en
Publication of CN103164332A publication Critical patent/CN103164332A/en
Application granted granted Critical
Publication of CN103164332B publication Critical patent/CN103164332B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Abstract

The invention relates to a computer operating system, discloses a detection and processing method of an endless loop task in the computer operating system, and solves the problems that detection of the endless loop task occupies lots of central processing unit (CPU) source and a detection method is complex in the traditional technology. The detection and processing method of the endless loop task is characterized in that a. generating an endless loop monitoring task with a highest priority and an endless loop detection task with a lowest priority of all tasks in the system; b. using the endless loop monitoring task and the endless loop detection task to detect if an endless loop appears in a task of the system, if the endless loop appears, then entering step c, or returning to step b; c. locating the task in which the endless loop appears in the system; d. suspending the task in which endless loop appears through the endless monitoring task, analyzing and searching the location of the endless loop; e. and releasing the relative source. The detection and processing method of the endless loop task is suitable for the operating system based on priorities.

Description

The detection of endless loop task and disposal route
Technical field
The present invention relates to computer operating system, particularly the detection of endless loop task and disposal route in computer operating system.
Background technology
Detection and the processing thereof of relevant endless loop task are very important technology in computer operating system.Application number be 01112526.8 " under endless loop under real-time multitask endless loop process method " described a kind of in Real-time Multi-task System the task abnormity operation a kind of monitoring and the disposal route of endless loop or class endless loop appear, its basic thought is: switch Hook Function with system clock interrupt service routine ISR and task and come the working time of monitor task, think that greater than the threshold values of setting endless loop has appearred in this task if the working time of certain task detected; The method can consume cpu resource in a large number.
All there is identical shortcoming in the method that similarly adopts system clock interrupt service routine and task switching Hook Function to detect endless loop with above-mentioned patent.
Another application number is that 200610020335.5 " a kind of endless loop or class endless loop task detection method " described the monitor task with limit priority, the test assignment of lowest priority detects the method for endless loop, it has been evaded employing system clock interrupt service routine and has detected the problem that endless loop causes a large amount of cpu resources of consumption, but the method need to ceaselessly be adjusted the priority of test assignment, and method is more complicated still.
Summary of the invention
Technical matters to be solved by this invention is: propose a kind of detection and disposal route of endless loop task, solve the problem that can take a large amount of cpu resources and detection method complexity in conventional art to the detection of endless loop task.
The present invention solves the problems of the technologies described above the scheme that adopts: the detection of endless loop task and disposal route comprise the following steps:
A. system generates endless loop monitor task and the endless loop Detection task with lowest priority with limit priority;
B. the endless loop Detection task moved after every sleep a period of time, and recorded the moment when moving; Whether the endless loop monitor task moved after every sleep a period of time, and detect and to have task endless loop to occur, if having, entered step c, otherwise returned to step b;
C. the task of endless loop occurring is positioned;
D. the endless loop monitor task is hung up and the task of endless loop occurred, and analyzes, searches the position that endless loop occurs;
E. related resource is discharged.
Further, in step b, the length of one's sleep of described endless loop Detection task is short than the length of one's sleep of endless loop monitor task.
Further, in step b, described endless loop monitor task detects the method that whether has task endless loop to occur: if current working time of endless loop monitor task and last endless loop Detection task working time the interval greater than the time threshold of presetting, endless loop appears in the task that is determined with.
Further, in step c, the concrete grammar that the task of right appearance endless loop positions is:
C1. endless loop monitor task judgement endless loop detects indexed variable, turns c5 if endless loop detects the state of indexed variable for endless loop occurring, otherwise execution in step c2;
C2. the standard interface by computer operating system obtains the task control block (TCB) list in system, and the user's reserved field in task control block (TCB) is expanded: interpolation task be scheduled field and task accumulated running time field constantly, and it is set to 0;
C3. switch Hook Function to the computer operating system registered task;
C4. the endless loop monitor task arranges state that endless loop detects indexed variable for endless loop occurring, and going forward side by side into the sleep state in the location of startup endless loop task, initiatively abdicates CPU, returns to step c1;
C5. detect the accumulated running time task control block variable of long task, the task of this variable record is the task of endless loop occurring;
C6. nullify chartered task and switch Hook Function, remove the endless loop sign, remove the working time of the task control block variable of long task.
Further, in step c3, described task switch Hook Function be used for the task of current execution and the task that will be scheduled between switch.
further, in step c4, after the endless loop monitor task is initiatively abdicated CPU, in system, endless loop task and priority will be dispatched higher than the task of endless loop task priority, switching between these tasks can be called the task switching Hook Function of registration, Hook Function is when being called operation, for the constantly scheduling in the task controll block of its scheduling of the task record that will be scheduled field constantly, and for the task of completing scheduling, current time deducts scheduling constantly, its difference is to complete scheduler task in the time of this dispatching office operation, then accumulated running time in the task controll block in field the time cumulation of this operation, if working time, the task control block variable of long task did not also record the task control block (TCB) of the longest task working time, the task control block (TCB) of scheduler task completed in record, otherwise, if the time of completing accumulative total in the task control block (TCB) of scheduler task is greater than time of accumulative total in the task control block (TCB) of long task working time of having recorded, with working time the task control block variable record of long task complete the task control block (TCB) of scheduler task.
Further, in steps d, after hanging up endless loop task, utilize user interface function log information, this task stack of standard interface Functional Analysis that utilizes computer operating system to provide is accurately located the position that endless loop occurs.
Further, in step e, described related resource comprises: the task of registration is switched Hook Function, endless loop indexed variable and the described working time task control block variable of long task.
The invention has the beneficial effects as follows: in the operating system based on non-round-robin, only need to start the endless loop monitor task of a limit priority and the endless loop Detection task of lowest priority, endless loop task has appearred in the system that just can detect, do not go out in system under the situation of endless loop, it is very low that endless loop monitor task and endless loop Detection task account for cpu resource; By the task control block (TCB) list of endless loop monitor task structure Priority-based with to system registry task switching Hook Function, Hook Function only need to record the scheduling moment of the task that will be scheduled when carrying out, finish the work for scheduling, deduct scheduling constantly when only needing use current, its difference is exactly the time of these management and running, then accumulated running time, and record the task control block (TCB) of the longest task of accumulated running time, so just can specifically navigate to endless loop task, the method for location endless loop is simple; The most backward System Reports endless loop task, system hangs up endless loop task, and utilize the standard interface function that system provides that the storehouse of endless loop task is analyzed, navigate to the specific code position that endless loop occurs, facilitate programmer's misarrangement, and need the cancellation task to switch Hook Function to reduce the consumption to cpu resource after navigating to endless loop task.
Description of drawings
Fig. 1 is endless loop monitor task operational scheme;
Fig. 2 is endless loop Detection task operational scheme;
Fig. 3 is detection and the process flow figure of endless loop task.
Embodiment
For can take the problem of a large amount of cpu resources and detection method complexity in conventional art to the detection of endless loop task, the present invention proposes a kind of detection and disposal route of endless loop task, basic thought of the present invention is: in the preemptive priority formula operating system of non-round-robin, high-priority task only otherwise block or initiatively abdicate CPU, other task of low priority task or equal priority principle that just can not obtain dispatching so, endless loop task will take a large amount of cpu resources, and its concrete manifestation form is that endless loop task accumulated running time is the longest;
therefore, the present invention generates the endless loop monitor task with limit priority and has the endless loop test assignment of lowest priority in implementation process, by the task control block (TCB) list of endless loop monitor task structure Priority-based with to system registry task switching Hook Function, Hook Function only need to record the scheduling moment of the task that will be scheduled when carrying out, finish the work for scheduling, deduct scheduling constantly when only needing use current, its difference is exactly the time of these management and running, then accumulated running time, and record the task control block (TCB) of the longest task of accumulated running time, so just can specifically navigate to endless loop task, the method of location endless loop is simple, the most backward System Reports endless loop task, system hangs up endless loop task, and utilize the standard interface function that system provides that the storehouse of endless loop task is analyzed, navigate to the specific code position that endless loop occurs, facilitate programmer's misarrangement, and need the cancellation task to switch Hook Function to reduce the consumption to cpu resource after navigating to endless loop task.
If the priority of task is 0~100, priority 0 is minimum, and priority 1 00 is the highest, adopts mode of the present invention, and the priority of the circularly monitoring task of checkmating is made as 100, and the priority of the cycle detection of checkmating task is made as 0;
For guaranteeing that endless loop monitor task and endless loop Detection task do not take a large amount of CPU, all operations in cycle of endless loop monitor task and endless loop Detection task, namely every sleep fixed cycle is moved once.Wherein, the every sleep longer cycle of monitor task moves once, and the every sleep of Detection task operation than the short period operation once.The cycle here is an empirical value.As Fig. 1, the moment of record operation during endless loop Detection task each run, as Fig. 2, when during endless loop monitor task each run, relatively current time moves with the endless loop Detection task, the moment of record compares, can calculate the endless loop Detection task has and how long has not moved, and namely has and how long is not dispatched, if this time is long, surpassed the threshold values that sets in advance, thought that system has task endless loop or class endless loop to occur.
On concrete enforcement, the detection of the endless loop task in the present invention and disposal route, referring to Fig. 3, it comprises the following steps:
1, endless loop monitor task and endless loop Detection task have judged whether that endless loop has appearred in task, if execution in step 2 of endless loop has appearred in system, otherwise return to step 1; Wherein, the method that endless loop appears in the task of judging whether is: if current working time of endless loop monitor task and last endless loop Detection task working time the interval greater than default time threshold, endless loop appears in the task that is determined with.
2, the task of occurring endless loop in system is positioned, concrete grammar is:
2a, judgement endless loop detect indexed variable, if detecting indexed variable, endless loop shows that beginning to locate endless loop task turns 2e, otherwise execution in step 2b, it is an overall integer variable that the endless loop here detects indexed variable, if its value is 1 to show and begin to locate endless loop task, if 0 does not also begin to locate endless loop task;
2b, the standard interface by computer operating system obtain the task control block (TCB) list in system, and the user's reserved field in task control block (TCB) are expanded: interpolation task be scheduled field and task accumulated running time field constantly, and it is set to 0; Working time, the task control block variable of long task set to 0.For certain task T, task is scheduled and constantly is designated as Tt0, and task accumulated running time is designated as Tt, and the task control block (TCB) here is the task control architecture that defines in multiple task operating system.
2c, switch Hook Function to the computer operating system registered task;
2d, endless loop monitor task arrange endless loop to detect indexed variable are 1 to begin to locate endless loop task to show, enter sleep state, initiatively abdicate CPU, return to step 2a;
The endless loop monitor task is after abdicating CPU, and in system, each preferentially will be obtained scheduling higher than task and the endless loop task of endless loop task priority, and Hook Function will repeatedly be carried out.The moment when Hook Function is carried out is t1, is T1 with being scheduled of task, and the task of completing scheduling is T0.For being scheduled of task T1, scheduling is current time constantly, T1t0=t1; Completing for scheduling of task T0, if T0t0 is non-zero constantly in scheduling, illustrate endless loop detected after this task be scheduled, so the scheduling finish the work be scheduled before this operation time be t=t1-T0t0, this time is accumulated in task accumulated running time T0t field, T0t=T0t+t, if working time the longest task TL task control block (TCB) also there is no record, accumulated running time the longest task task control block (TCB) be recorded as the task control block (TCB) of task T0; If record, accumulated running time of comparison task T0 and task TL, T0t>TLt, with working time the task control block variable of long task be recorded as the task control block (TCB) of task T0.
2e, detect the accumulated running time task control block variable of long task, the task of this variable record is the task of endless loop occurring;
2f, nullify chartered task and switch Hook Function, remove the endless loop sign, remove the working time of the task control block variable of long task.
3, the endless loop monitor task is hung up and the task of endless loop occurred, and analyzes, searches the position that endless loop occurs; The endless loop monitor task utilizes user interface function log information after hanging up and the task of endless loop occurring, and this task stack of standard interface Functional Analysis that utilizes computer operating system to provide is accurately located the position that endless loop occurs; The user interface function here is the interface that producer oneself realizes.
4, related resource is discharged: comprise the chartered Hook Function of cancellation, remove the endless loop sign, remove the working time of the task control block variable of long task.

Claims (9)

1. the detection of endless loop task and disposal route, is characterized in that, comprises the following steps:
A. system generates endless loop monitor task and endless loop Detection task with lowest priority of a limit priority;
B. the endless loop Detection task moved after every sleep a period of time, recorded current time during operation; Whether the endless loop monitor task moved after every sleep a period of time, and detect and to have task endless loop to occur, if having, entered step c, otherwise returned to step b;
C. the task of endless loop occurring is positioned;
D. the endless loop monitor task is hung up and the task of endless loop occurred, and analyzes, searches the position that endless loop occurs;
E. related resource is discharged.
2. the detection of endless loop task as claimed in claim 1 and disposal route, is characterized in that, in step b, the length of one's sleep of described endless loop Detection task is short than the length of one's sleep of endless loop monitor task.
3. the detection of endless loop task as claimed in claim 1 or 2 and disposal route, it is characterized in that, in step b, described endless loop monitor task detects the method that whether has task endless loop to occur: if current working time of endless loop monitor task and last endless loop Detection task working time the interval greater than the time threshold of presetting, endless loop appears in the task that is determined with.
4. the detection of endless loop task as claimed in claim 1 or 2 and disposal route, is characterized in that, in step c, the concrete grammar that the task of endless loop occurring is positioned is:
C1. the endless loop monitor task judges the endless loop indexed variable, if the state of endless loop indexed variable turns c5 for endless loop occurring, otherwise execution in step c2;
C2. obtain the task control block (TCB) list in system, and the user's reserved field in task control block (TCB) is expanded: interpolation task be scheduled constantly field and task accumulated running time field, and it is set to 0;
C3. switch Hook Function to the system registry task;
C4. the endless loop monitor task arranges state that endless loop detects indexed variable for endless loop occurring, and going forward side by side into the sleep state in the location of startup endless loop task, initiatively abdicates CPU, returns to step c1;
C5. detect the accumulated running time task control block variable of long task, the task of this variable record is the task of endless loop occurring;
C6. nullify chartered task and switch Hook Function, remove the endless loop sign, remove the working time of the task control block variable of long task.
5. the detection of endless loop task as claimed in claim 4 and disposal route, is characterized in that, in step c3, described task is switched Hook Function and is used for switching between the task of current execution and the task that will be scheduled.
6. the detection of endless loop task as claimed in claim 4 and disposal route, it is characterized in that, in step c4, after the endless loop monitor task is initiatively abdicated CPU, in system, endless loop task and priority will be dispatched higher than the task of endless loop task priority, switching between these tasks can be called the task switching Hook Function of registration, Hook Function is when being called operation, for the constantly scheduling in the task controll block of its scheduling of the task record that will be scheduled field constantly, and for the task of completing scheduling, current time deducts scheduling constantly, its difference is to complete scheduler task in the time of this dispatching office operation, then accumulated running time in the task controll block in field the time cumulation of this operation, if working time, the task control block variable of long task did not also record the task control block (TCB) of the longest task working time, the task control block (TCB) of scheduler task completed in record, otherwise, if the time of completing accumulative total in the task control block (TCB) of scheduler task is greater than time of accumulative total in the task control block (TCB) of long task working time of having recorded, with working time the task control block variable record of long task complete the task control block (TCB) of scheduler task.
7. the detection of endless loop task as claimed in claim 6 and disposal route, it is characterized in that, in steps d, after hanging up endless loop task, utilize user interface function log information, this task stack of standard interface Functional Analysis that utilizes computer operating system to provide is accurately located the position that endless loop occurs.
8. the detection of endless loop task as claimed in claim 7 and disposal route, it is characterized in that, in step e, described related resource comprises: the task of registration is switched Hook Function, endless loop indexed variable and the described working time task control block variable of long task.
9. the detection of endless loop task as claimed in claim 1 and disposal route, is characterized in that, in step b, be empirical value the length of one's sleep of endless loop Detection task.
CN201110422851.1A 2011-12-15 2011-12-15 The detection of endless loop task and disposal route Active CN103164332B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201110422851.1A CN103164332B (en) 2011-12-15 2011-12-15 The detection of endless loop task and disposal route

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201110422851.1A CN103164332B (en) 2011-12-15 2011-12-15 The detection of endless loop task and disposal route

Publications (2)

Publication Number Publication Date
CN103164332A true CN103164332A (en) 2013-06-19
CN103164332B CN103164332B (en) 2015-11-18

Family

ID=48587437

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201110422851.1A Active CN103164332B (en) 2011-12-15 2011-12-15 The detection of endless loop task and disposal route

Country Status (1)

Country Link
CN (1) CN103164332B (en)

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102622300A (en) * 2012-04-18 2012-08-01 迈普通信技术股份有限公司 Infinite loop or similar infinite loop detection method in multitask system
CN105427695A (en) * 2015-11-03 2016-03-23 中国农业大学 Automatic evaluation method and system for programming type examination question
CN105740080A (en) * 2016-03-11 2016-07-06 深圳市茁壮网络股份有限公司 Program sticking detection method and processor
CN106250316A (en) * 2016-08-09 2016-12-21 东软集团股份有限公司 A kind of endless loop detection method and device
CN106326066A (en) * 2015-07-07 2017-01-11 北京东土科技股份有限公司 Method and system for monitoring and adjusting task response performance of embedded system
CN113760700A (en) * 2020-08-06 2021-12-07 北京京东振世信息技术有限公司 Program endless loop detection method, device, electronic equipment and storage medium

Citations (3)

* Cited by examiner, † Cited by third party
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

Patent Citations (3)

* Cited by examiner, † Cited by third party
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

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102622300A (en) * 2012-04-18 2012-08-01 迈普通信技术股份有限公司 Infinite loop or similar infinite loop detection method in multitask system
CN106326066A (en) * 2015-07-07 2017-01-11 北京东土科技股份有限公司 Method and system for monitoring and adjusting task response performance of embedded system
CN106326066B (en) * 2015-07-07 2019-04-26 北京东土科技股份有限公司 A kind of method and its system of the monitoring adjustment of tasks of embedded system response performance
CN105427695A (en) * 2015-11-03 2016-03-23 中国农业大学 Automatic evaluation method and system for programming type examination question
CN105740080A (en) * 2016-03-11 2016-07-06 深圳市茁壮网络股份有限公司 Program sticking detection method and processor
CN105740080B (en) * 2016-03-11 2019-02-22 深圳市茁壮网络股份有限公司 A kind of stuck detection method of program and processor
CN106250316A (en) * 2016-08-09 2016-12-21 东软集团股份有限公司 A kind of endless loop detection method and device
CN113760700A (en) * 2020-08-06 2021-12-07 北京京东振世信息技术有限公司 Program endless loop detection method, device, electronic equipment and storage medium

Also Published As

Publication number Publication date
CN103164332B (en) 2015-11-18

Similar Documents

Publication Publication Date Title
CN103164332A (en) Detection and processing method of endless loop task
CN106293919B (en) A kind of the built-in tasks dispatching device and method of time trigger
US20120222043A1 (en) Process Scheduling Using Scheduling Graph to Minimize Managed Elements
US20130117759A1 (en) Network Aware Process Scheduling
CN109684060B (en) Mixed scheduling method for multiple types of time-critical tasks
GB2425628A (en) Programming distributed system using data flow diagrams
CN102622300B (en) Infinite loop or similar infinite loop detection method in multitask system
CN103995742B (en) Embedded type real-time scheduling control device and method based on MCU
CN101853191B (en) Method for detecting task endless loop in operating system and operating system
CN102270156A (en) Method for managing real-time embedded system timers
CN101561778B (en) Method for detecting task closed loop of multi-task operating system
CN100394399C (en) Method for testing closed loop or similar closed loop task
CN103346902A (en) Method and system for data collection and scheduling
KR101733534B1 (en) Schedulability analysys method and system for task group of hard real-time
CN102339029B (en) Method for realizing timing protection of embedded operating system
Kodase et al. Transforming structural model to runtime model of embedded software with real-time constraints
CN110794759B (en) PLC task scheduling method and device
Negrean et al. Bounding mode change transition latencies for multi-mode real-time distributed applications
Nahas et al. Ways for implementing highly-predictable embedded systems using time-triggered co-operative (TTC) architectures
Matsikoudis et al. On the schedulability of real-time discrete-event systems
CN102495793B (en) Method for detecting endless loop task
Mäki-Turja et al. Efficient development of real-time systems using hybrid scheduling
JP2009048358A (en) Information processor and scheduling method
KR101725408B1 (en) Tasks scheduling method for realtime operating system
CN103106111B (en) The detection system of task priority reversion in multiple task operating system and method

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