CN112015525A - Task process blocking management method - Google Patents

Task process blocking management method Download PDF

Info

Publication number
CN112015525A
CN112015525A CN201910454326.4A CN201910454326A CN112015525A CN 112015525 A CN112015525 A CN 112015525A CN 201910454326 A CN201910454326 A CN 201910454326A CN 112015525 A CN112015525 A CN 112015525A
Authority
CN
China
Prior art keywords
file
task
identification
identification file
running
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.)
Pending
Application number
CN201910454326.4A
Other languages
Chinese (zh)
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.)
Shanghai Bilibili Technology Co Ltd
Original Assignee
Shanghai Bilibili 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 Shanghai Bilibili Technology Co Ltd filed Critical Shanghai Bilibili Technology Co Ltd
Priority to CN201910454326.4A priority Critical patent/CN112015525A/en
Publication of CN112015525A publication Critical patent/CN112015525A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • G06F9/4881Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues

Abstract

The invention relates to a task process blocking management method, and belongs to the technical field of internet. When the method of the invention is adopted, when the second process of the task is started, whether the identification file exists is firstly judged; if yes, writing the second process number into the identification file and entering a blocking state; after monitoring that the identification file is modified, the first process saves the progress and quits; the second process then starts running, and further second processes may open the lock file in an exclusive manner in the blocked state, thereby preventing subsequent processes from entering the block. The timing trigger task is guaranteed that only one process processes data processing at the same time, the later process can cover the previous process operation, the previous process progress interruption can not be caused in the process of process handover, the problem of coexistence of multiple processes of the timing trigger process and the problem of progress interruption in the handover process are effectively solved, the process switching process is smooth, resources are saved, and efficient and safe operation of a server is facilitated.

Description

Task process blocking management method
Technical Field
The invention relates to the technical field of internet, in particular to the technical field of server process management methods, and specifically relates to a task process blocking management method.
Background
In the existing internet technology, there are two types of server background task processing modes: one is resident memory and the other is a timing task. When the code or configuration is updated, the process cannot be automatically loaded, and the risk of dead process or memory overflow is high. And the process triggered by the timing task, the code or the configuration can be automatically loaded when being updated, and the requirement on the memory is smaller.
However, the main problem of the timing task is that if the front process is still running when the back process is triggered, the same data is processed repeatedly, which is a waste of computing resources and may even cause data exception. The linux server manages a type of process, which is a common form of process management in the current internet technology. Such processes are triggered by the same timing task, and the running time of one process may exceed the triggering interval of two times, so that the blocking process is required.
Generally, a task refers to a series of processes that execute the same code flow to achieve the same purpose; the blocking means that only one process can process the same task in the same time period, that is, when the next process starts and the previous process does not end, the previous process is ended as soon as possible by effective control, and the next process is suspended.
Timing tasks generally have three blocking processing strategies, one is that the following processes are queued for waiting, but process accumulation is easily caused; secondly, killing the previous process, but if the previous process has unprocessed data, the progress is lost; and thirdly, the process after discarding, the process before will degenerate into a process of resident memory, losing the advantage of timing task.
Therefore, how to provide a smoother and resource-saving task process blocking method to further implement a more efficient and safer iteration mode of the same task process becomes a problem to be solved in the field.
Disclosure of Invention
The invention aims to overcome the defects in the prior art and provide a task process blocking management method which is smoother, saves resources and is beneficial to realizing an efficient and safe same task process iteration mode.
In order to achieve the above object, the task process blocking management method of the present invention comprises the steps of:
starting a first process for running a task, and writing an identifier of the first process into an identifier file;
starting a second process of the task, and determining whether to start running the second process according to the identification file and the identification of the second process;
and when the first process is still running and the second process does not start running in a blocking state, setting the lock file corresponding to the identification file to be exclusively owned by the second process, and writing the identification of the second process into the identification file.
In the method for managing task process blocking, the steps may specifically include the following steps:
starting a first process of a task, establishing an identification file of the task, writing a first process number in the identification file, and starting to run the first process;
monitoring whether the identification file is modified or not at regular time in the running process of the first process; when the first process is finished, deleting the identification file;
starting a second process of the task, and judging whether the identification file of the task exists or not;
if the identification file does not exist, establishing a new identification file of the task, writing a second process number in the new identification file, and starting to run the second process;
if the identification file exists, entering the blocking state, writing a second process number into the existing identification file, and monitoring the running state of the first process at regular time;
when the first process monitors that the identification file is modified, the processing progress is saved, and the first process is exited;
when the first process is finished, starting to run the second process and closing the lock file;
and when the first process is not finished after the set time, abandoning and exiting the second process, and closing the lock file.
In the task process blocking management method, the identification file comprises an absolute file path of the process.
In the method for managing task process blocking, the step of judging whether the identification file of the task exists specifically includes:
searching whether an identification file exists, and if not, indicating that the identification file of the task does not exist; if the process is found, acquiring an absolute file path of the process in the identification file, comparing whether the acquired absolute file path is consistent with the absolute file path of the second process, if so, indicating that the identification file of the task exists, and if not, indicating that the identification file of the task does not exist.
In the method for managing task process blocking, the writing of the second process number into the existing identification file specifically comprises the following steps:
and covering the first process number in the existing identification file with the second process number.
In the task process blocking management method, the first process regularly monitors whether the identification file is modified during the running process, and the specific steps are as follows:
and in the running process of the first process, regularly monitoring whether the process number in the identification file is the first process number.
In the task process blocking management method, the set elapsed time is 30 seconds.
In the task process blocking management method,
when the first process of the task is started, further comprising the step of,
establishing a lock file associated with the identification file of the task;
when the identification file exists, before writing the second process number into the existing identification file, the method further comprises the following steps:
opening the lock file in an exclusive manner;
and closing the lock file until the second process starts to run or quits.
The present invention also provides a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements the above-described task process blocking management method.
The invention also provides a task process blocking management device, which comprises a processor and a memory, wherein the memory is stored with a computer program, and the computer program is executed by the processor to realize the task process blocking management method.
When the second process of the task is started, whether the identification file exists or not is judged firstly; if the first process number exists, the first process number is not ended, the blocking state is entered, and the second process number is written into the existing identification file; after monitoring that the identification file is modified, the first process saves the processing progress and exits; and then the second process establishes a new identification file, writes the second process number and starts to run. The task process blocking management method ensures that only one process processes data at the same time for the timed triggered task, the later process can cover the operation of the former process, and meanwhile, in the process of process handover, the catcher of the later process cannot cause the interruption of the processing progress of the former process, thereby effectively solving the problems that the timed triggered task easily generates multi-process coexistence and the progress interruption in the process handover. Therefore, the process switching process is smoother, resources are saved, efficient and safe operation of the server is facilitated, the task process blocking management method is simple and convenient in application mode, and wide in application range.
Drawings
Fig. 1 is a flowchart of the steps of a task process blocking management method according to the present invention.
Fig. 2 is a flowchart illustrating steps of an embodiment of the method for managing task process blocking according to the present invention, wherein a lock file is set.
Detailed Description
In order to clearly understand the technical contents of the present invention, the following examples are given in detail.
Fig. 1 is a flowchart illustrating steps of a task process block management method according to the present invention.
In practical applications, the task process blocking management method of the present invention is an alternative implementation. The specific embodiments are illustrated by the following examples.
Example 1
The task process blocking management method comprises the following steps:
starting a first process for running a task, and writing an identifier of the first process into an identifier file;
starting a second process of the task, and determining whether to start running the second process according to the identification file and the identification of the second process;
and when the first process is still running and the second process does not start running in a blocking state, setting the lock file corresponding to the identification file to be exclusively owned by the second process, and writing the identification of the second process into the identification file. The processes of the same task run on the same machine (server). And a fixed file is designated as the task identification file on the machine, the process number of each process is written into the identification file when each process is started, and the identification file is deleted before quitting.
Starting a first process of a task, establishing an identification file of the task, writing a first process number in the identification file, and starting to run the first process; monitoring whether the identification file is modified or not at regular time in the running process of the first process; and when the first process is finished, deleting the identification file. .
And continuously acquiring the content of the file in the starting and running processes of the later process, and if the file does not exist, writing the current process number into the file and starting to execute the task.
That is, a second process of the task is started subsequently, and whether the identification file of the task exists is judged; if the identification file does not exist, establishing a new identification file of the task, writing a second process number in the new identification file, and starting to run the second process; if the identification file exists, entering the blocking state, writing a second process number into the existing identification file, and monitoring the running state of the first process at regular time; and when the first process monitors that the identification file is modified, saving the processing progress and exiting the first process.
If the identification file exists, at this time, if the process number recorded by the file is not consistent with the current process number, an absolute file path of the process is identified from the operation parameters of the process recorded by the file (the absolute path is obtained by using a command of 'pwdx process number' or 'lsof-a-p process number-d cwd'), if the absolute path is consistent with the file path of the current operation process and represents different processes of the same task, the process which is just started still operates.
That is, whether the identification file of the task exists is judged, whether the identification file exists needs to be searched, and if the identification file does not exist, the identification file of the task does not exist; if the process is found, an absolute file path of the process in the identification file is obtained, and the identification file comprises the absolute file path of the process. And comparing whether the acquired absolute file path is consistent with the absolute file path of the second process, if so, indicating that the identification file of the task exists, and if not, indicating that the identification file of the task does not exist.
At this time, if the new process is specified to run in the overlay mode, the process number of the new process is overlaid with the old process number in the identification file, and the running state of the old process is continuously detected in the next 30 seconds. If the new process does not specify the overlay mode, the new process can be exited directly upon detection of the old process.
That is to say that the first and second electrodes,
setting the lock file corresponding to the identification file to be exclusively occupied by the second process;
when the first process is finished, starting to run the second process;
and when the first process is not finished after the set time, abandoning and exiting the second process.
For the old process, if the change of the process number recorded by the identification file is detected, the new process is in the blockage, the old process safely exits after the processing progress is saved, and the new process takes over the processing.
That is, in the running process of the first process, whether the identification file is modified or not is regularly monitored, which may be whether the process number in the identification file is the first process number or not; and when the first process monitors that the identification file is modified, saving the processing progress and exiting the first process.
When the old process does not run any more, the new process starts to process data; if the old process is still running after 30 seconds, the new process gives up and exits.
When 30 seconds or other predetermined time has elapsed without the first process terminating, the second process is aborted and exited.
Example 2
The difference from embodiment 1 is that before overwriting the old process number, to prevent another new process from entering, a lock file (which may be in the form of a file name identification plus a constant suffix name) needs to be opened in an exclusive manner until the new process enters the processing state or exits, and the lock is released. The specific flow is shown in fig. 2. In the locking process, if a second new process tries to execute the same covering process number operation as the first new process, the locking is failed and the direct exit is carried out, and only one new process is ensured to be in a blocking state at the same time.
That is, when the first process of the task is started, the identification file and the lock file associated with the identification file of the task are simultaneously established; when the identification file exists, before writing the second process number into the existing identification file, the method further comprises: opening the lock file in an exclusive manner; and closing the lock file until the second process starts to run or quits.
The lock file is used for preventing the second process from waiting for the first process to finish, and the identification file is updated by the third process.
Specifically, in this embodiment, two files are used, one is an identification file (pid file-xxx/pid) for identifying the id of the currently running process, and the other is a lock file (pid lock file xxx/pid.
The identification file is used for verifying whether the process is switched in the current running process.
The lock file is used in the process waiting process to prevent queuing waiting, and the lock file is released after the blocking state is finished.
For example:
when the first process exits, the second process enters an operating state, or the second process waits for overtime exit, the lock file is released; if the third process is started again in the waiting process of the second process, the third process can directly quit due to locking failure (the lock file which is exclusively opened by the second process cannot be opened); if the second process waits for the timeout to exit, the third process is initiated because the lock file has been released at the time the second process timed out, and the third process operates as the second process does.
Example 3
Taking a ticketing system as an example, the task process blocking management method of the invention is used for carrying out a plurality of scenes such as asynchronous ordering, message notification sending, asynchronous batch refund and the like, thereby not only ensuring the real-time processing, but also avoiding the problems of dead process or memory overflow caused by long-time running of the process.
Specifically, taking an asynchronous order placing task as an example, a user request is temporarily stored in a queue, then the asynchronous order placing task is triggered every 1 minute to consume data in the queue, a process number of the process is recorded in/[ path _ of _ task ]/pid as soon as the process is started, and after a batch of data is processed, the content of the pid file is checked. After one minute, the process two is started, firstly, the content of the pid file is checked, if the pid exists, the path of the process file is judged through the pwdx process number, the same path as the file path of the process two is found, the covering operation is determined, then the process two locks a file/[ path _ of _ task ]/pid.lock in an exclusive mode, then the process number of the process two is written into the pid file, and the survival of the process one is continuously checked in the next 30 seconds. At this time, the first process checks the pid file and finds that the process number is changed, so that the first process actively exits when the data in the memory is processed, and the second process checks that the first process does not survive any more, releases the lock file and enters the running state. If process three starts after 1 minute, it decides to override the run after checking the pid, but fails when locking the pid.
The invention also provides a task process blocking management device and a computer readable storage medium. The task process blocking management device comprises a processor and a memory, wherein the memory is a computer readable storage medium and is stored with a computer program. When executed by the processor, the computer program implements the task process blocking management method described in the above embodiments.
When the second process of the task is started, whether the identification file exists or not is judged firstly; if the first process number exists, the first process number is not ended, the blocking state is entered, and the second process number is written into the existing identification file; after monitoring that the identification file is modified, the first process saves the processing progress and exits; and then running a second process and closing the lock file. The task process blocking management method ensures that only one process processes data at the same time for the timed triggered task, the later process can cover the operation of the former process, and meanwhile, in the process of process handover, the catcher of the later process cannot cause the interruption of the processing progress of the former process, thereby effectively solving the problems that the timed triggered task easily generates multi-process coexistence and the progress interruption in the process handover. Therefore, the process switching process is smoother, resources are saved, efficient and safe operation of the server is facilitated, the task process blocking management method is simple and convenient in application mode, and wide in application range.
In this specification, the invention has been described with reference to specific embodiments thereof. It will, however, be evident that various modifications and changes may be made thereto without departing from the broader spirit and scope of the invention. The specification and drawings are, accordingly, to be regarded in an illustrative rather than a restrictive sense.

Claims (10)

1. A method for task process blocking management, the method comprising the steps of:
starting a first process for running a task, and writing an identifier of the first process into an identifier file;
starting a second process of the task, and determining whether to start running the second process according to the identification file and the identification of the second process;
and when the first process is still running and the second process does not start running in a blocking state, setting the lock file corresponding to the identification file to be exclusively owned by the second process, and writing the identification of the second process into the identification file.
2. The task process blocking management method according to claim 1,
the step of writing the identifier of the first process into the identifier file when the first process for running the task is started is specifically as follows:
starting a first process of a task, establishing an identification file of the task, writing a first process number in the identification file, and starting to run the first process;
monitoring whether the identification file is modified or not at regular time in the running process of the first process; when the first process is finished, deleting the identification file;
the step of determining whether to start running the second process according to the identifier file and the identifier of the second process, of the second process for starting the task, specifically includes:
starting a second process of the task, and judging whether the identification file of the task exists or not;
if the identification file does not exist, establishing a new identification file of the task, writing a second process number in the new identification file, and starting to run the second process;
if the identification file exists, entering the blocking state, writing a second process number into the existing identification file, and monitoring the running state of the first process at regular time;
when the first process monitors that the identification file is modified, the processing progress is saved, and the first process is exited;
when entering a blocking state in which the first process is still running and the second process does not start running, setting the lock file corresponding to the identifier file to be exclusively owned by the second process, and writing the identifier of the second process into the identifier file specifically includes:
setting the lock file corresponding to the identification file to be exclusively occupied by the second process;
when the first process is finished, starting to run the second process and closing the lock file;
and when the first process is not finished after the set time, abandoning and exiting the second process, and closing the lock file.
3. A task process block management method according to claim 2, wherein said markup file includes an absolute file path of the process.
4. The method for managing task process blocking according to claim 3, wherein the determining whether the markup file of the task exists specifically includes:
searching whether an identification file exists, and if not, indicating that the identification file of the task does not exist; if the process is found, acquiring an absolute file path of the process in the identification file, comparing whether the acquired absolute file path is consistent with the absolute file path of the second process, if so, indicating that the identification file of the task exists, and if not, indicating that the identification file of the task does not exist.
5. The method for task process block management according to claim 2, wherein the writing of the second process number into an existing markup file specifically comprises:
and covering the first process number in the existing identification file with the second process number.
6. The method for task process block management according to claim 5, wherein the first process periodically monitors whether the markup file is modified during running, specifically:
and in the running process of the first process, regularly monitoring whether the process number in the identification file is the first process number.
7. The task process blocking management method according to claim 2, wherein the set time is 30 seconds.
8. The task process blocking management method according to claim 2,
when the first process of the task is started, further comprising the step of,
establishing a lock file associated with the identification file of the task;
when the identification file exists, before writing the second process number into the existing identification file, the method further comprises the following steps:
opening the lock file in an exclusive manner;
and closing the lock file until the second process starts to run or quits.
9. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out a method of task process blockage management according to any one of claims 1 to 8.
10. A task process blocking management apparatus comprising a processor and a memory, said memory having stored thereon a computer program, wherein the computer program, when executed by said processor, implements the task process blocking management method according to any one of claims 1 to 8.
CN201910454326.4A 2019-05-29 2019-05-29 Task process blocking management method Pending CN112015525A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910454326.4A CN112015525A (en) 2019-05-29 2019-05-29 Task process blocking management method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910454326.4A CN112015525A (en) 2019-05-29 2019-05-29 Task process blocking management method

Publications (1)

Publication Number Publication Date
CN112015525A true CN112015525A (en) 2020-12-01

Family

ID=73501156

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910454326.4A Pending CN112015525A (en) 2019-05-29 2019-05-29 Task process blocking management method

Country Status (1)

Country Link
CN (1) CN112015525A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116339956A (en) * 2023-05-29 2023-06-27 天翼云科技有限公司 Distribution method and device of configuration tasks, electronic equipment and storage medium

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20110271087A1 (en) * 2010-04-30 2011-11-03 International Business Machines Corporation Embedding process identification information in a pathname to indicate process status
CN102693159A (en) * 2012-05-09 2012-09-26 上海晨思电子科技有限公司 Method and device for controlling hardware equipment based on user mode multitask
US20140373023A1 (en) * 2013-06-12 2014-12-18 Fujitsu Limited Exclusive control request allocation method and system
US20170004013A1 (en) * 2014-02-14 2017-01-05 Shell Internet (Beijing) Security Technology Co., Ltd. Method and device for managing application
CN106557360A (en) * 2016-11-09 2017-04-05 青岛海信电器股份有限公司 Task run method and device
CN106775980A (en) * 2016-12-15 2017-05-31 北京奇虎科技有限公司 A kind of process ID management method, device and computer-readable medium
CN108509260A (en) * 2018-01-31 2018-09-07 深圳市万普拉斯科技有限公司 Thread identifying processing method, apparatus, computer equipment and storage medium

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20110271087A1 (en) * 2010-04-30 2011-11-03 International Business Machines Corporation Embedding process identification information in a pathname to indicate process status
CN102693159A (en) * 2012-05-09 2012-09-26 上海晨思电子科技有限公司 Method and device for controlling hardware equipment based on user mode multitask
US20140373023A1 (en) * 2013-06-12 2014-12-18 Fujitsu Limited Exclusive control request allocation method and system
US20170004013A1 (en) * 2014-02-14 2017-01-05 Shell Internet (Beijing) Security Technology Co., Ltd. Method and device for managing application
CN106557360A (en) * 2016-11-09 2017-04-05 青岛海信电器股份有限公司 Task run method and device
CN106775980A (en) * 2016-12-15 2017-05-31 北京奇虎科技有限公司 A kind of process ID management method, device and computer-readable medium
CN108509260A (en) * 2018-01-31 2018-09-07 深圳市万普拉斯科技有限公司 Thread identifying processing method, apparatus, computer equipment and storage medium

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116339956A (en) * 2023-05-29 2023-06-27 天翼云科技有限公司 Distribution method and device of configuration tasks, electronic equipment and storage medium
CN116339956B (en) * 2023-05-29 2023-10-10 天翼云科技有限公司 Distribution method and device of configuration tasks, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
CN108419279B (en) Network switching system
WO2017070894A1 (en) Terminal-based wakelock control method and apparatus, and terminal
US7017082B1 (en) Method and system for a process manager
JPH05197698A (en) Debugging system for decentralized information processing system
CN103793246A (en) Method and system for coordinating camera resources
US6892331B2 (en) Method and system for error detection in a managed application environment
CN112991635B (en) Storage and taking method and device for intelligent cabinet
CN113835985B (en) Method, device and equipment for monitoring and analyzing jamming reason
CN112463066B (en) Method and equipment for controlling burst service quality of distributed block storage logical volume
US20190196864A1 (en) Process Processing Method and Apparatus
CN112015525A (en) Task process blocking management method
CN114003396A (en) Method, device and equipment for processing kernel soft deadlock and storage medium
CN113542256A (en) Method, device, equipment and storage medium for updating login credentials in client
CN107634868B (en) Method and system for managing network service
CN106911680B (en) Strategy issuing method and device
CN112463348B (en) Timed task processing method and device
CN116501465A (en) Automatic driving task execution method and device, electronic equipment and storage medium
CN105930215A (en) Control method and control device for mobile terminal
CN111898116B (en) Cache-based industrial white list learning method and system
CN112463174A (en) Method, device, equipment and storage medium for remotely unloading server
JPH10327212A (en) Network connection control system and storage medium
CN113094075A (en) Firmware upgrading method and device, terminal equipment and computer readable storage medium
CN112804108A (en) Signaling execution method and device, electronic equipment and machine-readable storage medium
CN117555717B (en) Application exception handling method, terminal and computer storage medium
CN110308943B (en) Program running method and device, computing equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination