CN109062686B - Multi-process management method, storage medium, electronic device and system - Google Patents

Multi-process management method, storage medium, electronic device and system Download PDF

Info

Publication number
CN109062686B
CN109062686B CN201810746906.6A CN201810746906A CN109062686B CN 109062686 B CN109062686 B CN 109062686B CN 201810746906 A CN201810746906 A CN 201810746906A CN 109062686 B CN109062686 B CN 109062686B
Authority
CN
China
Prior art keywords
function
auxiliary
auxiliary process
task
main process
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
Application number
CN201810746906.6A
Other languages
Chinese (zh)
Other versions
CN109062686A (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.)
Wuhan Douyu Network Technology Co Ltd
Original Assignee
Wuhan Douyu Network 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 Wuhan Douyu Network Technology Co Ltd filed Critical Wuhan Douyu Network Technology Co Ltd
Priority to CN201810746906.6A priority Critical patent/CN109062686B/en
Publication of CN109062686A publication Critical patent/CN109062686A/en
Application granted granted Critical
Publication of CN109062686B publication Critical patent/CN109062686B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

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/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • 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/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention discloses a multi-process management method, a storage medium, electronic equipment and a system, and relates to the technical field of control, wherein the method comprises the steps of calling a CreateNamepPepe function in an API function of a Windows system to create a plurality of named pipelines for communication between a main process and an auxiliary process, and each named pipeline corresponds to one auxiliary process; the main process calls a function WriteFile to write task data in a named pipeline and sends the written task data to a corresponding auxiliary process; the auxiliary process calls a function ReadFile to read task data from the named pipeline; and the auxiliary process executes the corresponding task based on the task data, and calls a function AtExit to finish self exit after the task is executed. In the invention, the main process masters the task execution state of the auxiliary process through the named pipeline, so that the normal operation of the application program under the condition of operating multiple auxiliary processes is ensured.

Description

Multi-process management method, storage medium, electronic device and system
Technical Field
The invention relates to the technical field of control, in particular to a multi-process management method, a storage medium, electronic equipment and a system.
Background
Currently, for some service type applications, especially for applications with independent tasks, a multi-process architecture design is usually adopted, and a multi-process design is adopted, so that the instability of one process cannot cause the whole program to make mistakes, that is, for one service type application, when one process exits due to rushing, other processes can continue to perform services, and the multi-process has stronger robustness, so as to ensure the normal operation of the application.
In an actual operation process, for example, a main process may be created for receiving a task, and then a plurality of auxiliary processes (sub-processes) are created by the main process to complete different tasks, that is, for each received task, a single auxiliary process is used to complete the different tasks, that is, the different tasks create different auxiliary processes to complete the different tasks, such as a file searching task, a file writing task, a picture processing task, and the like. In actual operation, each auxiliary process cannot be guaranteed to operate stably, because the number of the auxiliary processes operating simultaneously is too large, data errors are generated when tasks of some auxiliary processes are executed to half, so that an application program runs fast, deadlock is generated by the tasks executed by some auxiliary processes, so that the application program is blocked, and a main process in the prior art does not have a good management scheme for the auxiliary processes.
Disclosure of Invention
Aiming at the defects in the prior art, the invention aims to provide a multi-process management method, wherein a main process controls the task execution state of an auxiliary process through a named pipeline, so that the normal operation of an application program under the condition of multi-auxiliary process operation is ensured.
In order to achieve the above purposes, the technical scheme adopted by the invention is as follows:
calling a CreateNamedPipe function in an API function of a Windows system to create a plurality of named pipelines for communication between a main process and an auxiliary process, wherein each named pipeline corresponds to one auxiliary process;
the main process calls a function WriteFile to write task data in a named pipeline and sends the written task data to a corresponding auxiliary process;
the auxiliary process calls a function ReadFile to read task data from the named pipeline;
the auxiliary process executes corresponding tasks based on the task data, calls a function AtExit to finish self exit after the tasks are executed, and sends data used for indicating that the tasks are executed and the auxiliary process exits to the main process through a named pipeline.
On the basis of the technical proposal, the device comprises a shell,
each auxiliary process correspondingly executes one task;
the name parameters are also required to be transmitted when the named pipeline is established;
the name parameter transmitted into the named pipeline is the name of the task to be executed by the auxiliary process corresponding to the named pipeline.
On the basis of the technical scheme, after the named pipeline is created, for the main process:
calling a function ConnectNamedPipe to wait for the auxiliary process corresponding to the named pipeline to be connected;
the auxiliary process to be received finishes the connection with the main process through the named pipeline, and the auxiliary process is received and data for indicating the successful connection is sent to the main process through the named pipeline;
calling a function ReadFile to read data sent by the auxiliary process;
and calling a function WriteFile to write task data in the named pipeline and sending the written task data to a corresponding auxiliary process.
On the basis of the technical scheme, after the named pipeline is created, for the auxiliary process:
calling a function CreateFile to connect the named pipeline and completing the connection with the main process;
sending data for indicating successful connection to the main process, and calling a function WaitNamedPipe to wait for the main process to correspond to the function;
and calling a function ReadFile to read the task data written by the main process from the named pipeline.
On the basis of the technical scheme, task completion time is preset in the main process, when the main process writes task data in the named pipeline and sends the written task data to the auxiliary process, if the main process does not receive data which is sent by the auxiliary process and used for indicating that the task is completely executed and the auxiliary process is quitted within the preset task completion time, the main process calls a function TerminateProcess to terminate the operation of the auxiliary process.
On the basis of the technical scheme, the method further comprises the following steps: and writing an exception handling function for monitoring the auxiliary process, finishing the registration of the exception handling function in the Windows system, informing the main process of the exception handling function by sending a log when the execution task of the auxiliary process is abnormal, and calling a function terminateProcess by the main process to terminate the operation of the auxiliary process.
On the basis of the technical scheme, when the auxiliary process is stopped to run, the main process recreates the auxiliary process to re-execute the task executed before the stopped auxiliary process.
The present invention also provides a storage medium having stored thereon a computer program which, when executed by a processor, performs the steps of:
calling a CreateNamedPipe function in an API function of a Windows system to create a plurality of named pipelines for communication between a main process and an auxiliary process, wherein each named pipeline corresponds to one auxiliary process;
the main process calls a function WriteFile to write task data in a named pipeline and sends the written task data to a corresponding auxiliary process;
the auxiliary process calls a function ReadFile to read task data from the named pipeline;
the auxiliary process executes corresponding tasks based on the task data, calls a function AtExit to finish self exit after the tasks are executed, and sends data used for indicating that the tasks are executed and the auxiliary process exits to the main process through a named pipeline.
The present invention also provides an electronic device, comprising:
the system comprises a creating unit, a processing unit and a processing unit, wherein the creating unit is used for calling a CreateNamedPipe function in a Windows system API function to create a plurality of named pipelines for communication between a main process and an auxiliary process, and each named pipeline corresponds to one auxiliary process;
the write-in unit is used for driving the main process to call the function WriteFile to write in the task data in the named pipeline and sending the written task data to the corresponding auxiliary process;
the reading unit is used for driving the auxiliary process to call a function ReadFile to read task data from a named pipeline;
and the execution and notification unit is used for driving the auxiliary process to execute the corresponding task based on the task data, calling a function AtExit by the auxiliary process to finish self exit after the task is executed, and sending data which is used for indicating that the task is executed and the auxiliary process exits to the main process through a named pipeline.
The present invention also provides a multiprocess management system, comprising:
the creating module is used for calling a CreateNamedPipe function in an API function of the Windows system to create a plurality of named pipelines for communication between the main process and the auxiliary process, and each named pipeline corresponds to one auxiliary process;
the write-in module is used for driving the main process to call the function WriteFile to write in the task data in the named pipeline and sending the written task data to the corresponding auxiliary process;
the reading module is used for driving the auxiliary process to call a function ReadFile to read task data from a named pipeline;
and the execution and notification module is used for driving the auxiliary process to execute the corresponding task based on the task data, calling a function AtExit by the auxiliary process to finish self exit after the task is executed, and sending data which is used for indicating that the task is executed and the auxiliary process exits to the main process through a named pipeline.
Compared with the prior art, the invention has the advantages that: the method comprises the steps that a named pipeline used for communication between a main process and an auxiliary process is created, task data are written into the created named pipeline by the main process, the task data are sent to the auxiliary process through the named pipeline, the auxiliary process executes corresponding tasks based on the task data, the auxiliary process calls a function AtExit to complete self exit after the tasks are executed, data used for indicating that the tasks are executed completely and the auxiliary process exits are sent to the main process through the named pipeline, the auxiliary process and the main process communicate through the created named pipeline, and meanwhile the main process grasps the task execution state of the auxiliary process through the named pipeline, so that normal operation of an application program under the operating condition of multiple auxiliary processes is guaranteed.
Drawings
FIG. 1 is a flowchart of a multi-process management method according to an embodiment of the present invention;
fig. 2 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings and examples. As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
Referring to fig. 1, an embodiment of the present invention provides a multi-process management method for managing an auxiliary process (sub-process) by a main process of an application running in a Windows system, and of course, the idea of the multi-process management method in the embodiment of the present invention can also be applied to a Linux system. The multi-process management method of the embodiment of the invention specifically comprises the following steps:
s1: calling a CreateNamepPepe function in a Windows system API (application Programming interface) function to create a plurality of named pipelines for communication between the main process and the auxiliary process, wherein each named pipeline corresponds to one auxiliary process. In the Windows system, the CreateNamedPipe function is used to perform named pipe creation. The invention discloses a naming pipeline, which is called a naming pipeline, can support reliable, unidirectional or bidirectional data communication between different processes of the same computer or different processes of different computers across a network, belongs to an interprocess communication mechanism.
In the running process of the application program, a plurality of tasks need to be executed, such as a file searching task, a file writing task, a picture processing task and the like, each task is executed by one auxiliary process correspondingly, namely each auxiliary process executes one task correspondingly, and all the auxiliary processes can execute the tasks simultaneously, so a plurality of named pipelines are created, and each auxiliary process uses one named pipeline to communicate with the main process.
The name parameters are transmitted into the function CreateNamdPipe, the name parameters transmitted into the named pipeline are the names of the tasks to be executed by the auxiliary process corresponding to the named pipeline, and the names of the tasks are different, so that the name of each named pipeline can be unique and cannot be renamed with other named pipelines, and the uniqueness of the corresponding relationship among the named pipeline, the tasks and the auxiliary process is further ensured.
S2: the main process calls a function WriteFile to write task data in the named pipeline and sends the written task data to the corresponding auxiliary process, the named pipeline and the auxiliary process are corresponding, and the task and the auxiliary process are corresponding, so the task data written in the named pipeline by the main process can be sent to the corresponding auxiliary process through the named pipeline, and the task data is a task to be executed by the auxiliary process, such as writing a file, reading a file and the like. The function WriteFile is a write data function common in Windows systems, and is often used to write data to files, and is also often used for handling communication devices, pipes, sockets, and mail slots.
For the main process, after the named pipe creation is completed, the specific operations executed by the main process are as follows:
a: and calling a function ConnectNamedPipe to wait for the connection of the auxiliary process corresponding to the named pipeline, wherein after the named pipeline is established, the auxiliary process is connected with the main process through the established named pipeline, and before the connection, the main process calls the function ConnectNamedPipe to wait for the connection of the auxiliary process. The function ConnectNamedPipe is used in Windows systems to instruct the server back-process to wait until the client or other process connects to the named pipe.
B: and the auxiliary process to be received finishes the connection with the main process through the named pipeline, and the auxiliary process is received and sends data for indicating the successful connection to the main process through the named pipeline. Namely, after the auxiliary process is connected with the named pipeline, the auxiliary process sends data to inform the main process.
C: and calling a function ReadFile to read the data sent by the auxiliary process. And the main process calls a function ReadFile to read the data sent by the auxiliary process, and the fact that the auxiliary process is successfully connected with the named pipeline is known. The function ReadFile is used to indicate that data is read into a file, i.e. to indicate that data is read.
D: and calling a function WriteFile to write task data in the named pipeline and sending the written task data to a corresponding auxiliary process. Since the tasks that need to be performed by different secondary processes are different, the task data written by the primary process is different for different secondary processes. The function WriteFile is a common function of writing data in a Windows system, i.e. writing data into a file.
For the auxiliary process, after the named pipe is created, the specific operations executed by the auxiliary process are as follows:
a: and calling a function CreateFile to connect the named pipeline and finish the connection with the main process. After the named pipe is created, the auxiliary process calls the function CreateFile to complete the connection between the auxiliary process and the named pipe, namely, the connection between the auxiliary process and the main process is completed. The function CreateFile is a multi-function in the Windows system that can be used to open or create objects and return accessible handles.
b: and the auxiliary process to be received finishes the connection with the main process through the named pipeline, and the auxiliary process is received and sends data for indicating the successful connection to the main process through the named pipeline. I.e. tells the main process that the secondary process has completed the connection. And after the main process is informed, the task is issued to the auxiliary process.
c: and calling a function ReadFile to read the data sent by the auxiliary process.
S3: the helper process calls the function ReadFile to read the task data from the named pipe. After the main process receives the notification that the auxiliary process is connected, the main process sends task data to the auxiliary process through a naming pipeline, and at the moment, the auxiliary process calls a function ReadFile to read the data sent by the auxiliary process to acquire the task content.
S4: the auxiliary process executes corresponding tasks based on the task data, calls a function AtExit to finish self exit after the tasks are executed, and sends data used for indicating that the tasks are executed and the auxiliary process exits to the main process through a named pipeline. The function AtExit is an API function of the Windows system, and is used to terminate the running of a function or a process, and the prototype of the function is int AtExit (void), where the parameter func represents a function that needs to be completed when the process or the program exits, and in the embodiment of the present invention, the function is to complete the execution of a task.
And compiling a process exit registration mechanism for each auxiliary process, calling a function AtExit to finish the exit of the auxiliary process when the task of the auxiliary process is completely executed, and sending data to inform that the task of the main process is completely executed and the auxiliary process is exited.
The method is characterized in that a function of inter-process communication is written for sending the notification data of the main process by the auxiliary process, so that the main process is informed that the task is completely executed and the auxiliary process is quitted. The inter-process communication can be performed by using many methods provided by the system, such as a network socket, a shared memory between processes, and the like. The embodiment of the invention uses the named pipeline created before to carry out the communication between the auxiliary process and the main process, at this time, the auxiliary process informs the main process that the task is completely executed and the auxiliary process is quitted, and the corresponding execution codes are as follows:
WriteFile(“process exit”);
}
Atexit(IpcExit);
that is, the function Atexit before the call is made to register the process exit function IpcExit, which is notified to the host process through the named pipe.
In a real-time mode, task completion time is preset in a main process, when the main process writes task data in a named pipeline and sends the written task data to an auxiliary process, if the main process does not receive data which is sent by the auxiliary process and used for indicating that a task is completely executed and the auxiliary process is quitted within the preset task completion time, the main process calls a function TerminateProcess to terminate the operation of the auxiliary process. The function TerminateProcess is a function in the C + + programming language for terminating a specified process or all threads.
The method comprises the steps that the approximate time for completing each task can be estimated in advance, the estimated task completing time is the task completing time preset in a main process, when task data are written into a named pipeline by the main process, the main process stores the creation time of the task, then the main process periodically facilitates the received data sent by an auxiliary process, if the main process does not receive the data which are sent by the auxiliary process and used for indicating that the task is completed and the auxiliary process exits, namely the time for the auxiliary process to execute the task exceeds the preset task completing time, the situation that the auxiliary process is possibly blocked is shown, the task cannot be normally executed, therefore, a function Terminateprocess is called to terminate the operation of the auxiliary process, and the waste of system resources caused by the continuous existence of a large number of blocked processes is prevented, and ensuring the normal operation of the application program.
The prototype of the function TerminateProcess is as follows:
BOOL TerminateProcess(
HANDLE hProcesses; // handle to be ended Process
UINT uExitCode; v/Exit code for specified Process
);
The process handle is a handle stored by the main process when the auxiliary process is created. When the condition that the auxiliary process is stuck is monitored, the function TerminateProcess is called to close the process, and therefore the situation that a large number of stuck processes exhaust system resources is effectively prevented.
In one implementation mode, an exception handling function for monitoring the auxiliary process is written, the exception handling function is registered in the Windows system, when the auxiliary process executes a task abnormally, the exception handling function informs the main process by sending a log, and the main process calls a function terminateProcess to terminate the operation of the auxiliary process. Exceptions are divide by 0 exceptions, invalid handle exceptions, memory access exceptions, and the like. For the auxiliary process to execute different tasks, it is difficult to ensure that all the tasks executed by the auxiliary process can be normally executed, so for the design of the application program, it is necessary to be compatible with the situation that the auxiliary process has an error, and when the error occurs, the error can be captured, so as to timely notify the main process that the task fails to be executed.
Firstly, writing an exception handling logic, which is concretely realized as follows:
LONG__stdcall
MyUnhandledExceptionFilter(PEXCEPTION_POINTERS
pExceptionInfo)
that is, an exception handling function is written, which is MyUnhandledExceptionFilter, where the parameter pexceptinfo is used to convey some exception-related information, such as what exception is at this time. In the exception handling function, a named pipeline created before needs to be called to inform the main process, so that the main process knows that the auxiliary process has an exception.
After the exception handling function is written, the function of registering the exception handling function is written. The Windows system also provides corresponding API functions to complete registration of exceptions: an exception handling function is registered first so that written exception handling logic is executed when an exception occurs in the process execution of an application. The system provides a corresponding API function to register an exception handling function, and the specific implementation is as follows:
SetUnhandledExceptionFilter(MyUnhandledExceptionFilter);
the system API function SetUnhandledExceptionFilter represents that an exception handling function is registered, and the parameter MyUnhandledExceptionFilter is the exception handling function written above.
After the exception handling function is registered, namely exception handling logic is registered in the Windows system, when an application program generates an exception during execution, the system executes the registered exception handling function MyUnhandledExceptionFilter and handles the exception in the function.
When the auxiliary process is stopped, the main process creates the auxiliary process again to execute the task executed before the stopped auxiliary process again, and the task is ensured to be continuously executed and the application program is normally operated.
The multi-process management method of the embodiment of the invention comprises the steps that a named pipeline used for communication between a main process and an auxiliary process is created, then task data is written into the created named pipeline by the main process, the task data is sent to the auxiliary process through the named pipeline, the auxiliary process executes corresponding tasks based on the task data, after the tasks are executed, the auxiliary process calls a function AtExit to finish self quitting, data used for indicating that the tasks are executed completely and the auxiliary process is quitted is sent to the main process through the named pipeline, the auxiliary process and the main process communicate through the created named pipeline, and meanwhile the main process grasps the task execution state of the auxiliary process through the named pipeline, so that the normal operation of an application program under the operating condition of the multi-auxiliary process is ensured.
An embodiment of the present invention further provides a storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the following steps:
calling a CreateNamedPipe function in an API function of a Windows system to create a plurality of named pipelines for communication between a main process and an auxiliary process, wherein each named pipeline corresponds to one auxiliary process;
the main process calls a function WriteFile to write task data in a named pipeline and sends the written task data to a corresponding auxiliary process;
the auxiliary process calls a function ReadFile to read task data from the named pipeline;
the auxiliary process executes corresponding tasks based on the task data, calls a function AtExit to finish self exit after the tasks are executed, and sends data used for indicating that the tasks are executed and the auxiliary process exits to the main process through a named pipeline.
Referring to fig. 2, an embodiment of the present invention further provides an electronic device, which includes a creating unit 501, a writing unit 502, a reading unit 503, and an executing and notifying unit 504.
The creating unit 501 is configured to call a CreateNamedPipe function in the API function of the Windows system to create a plurality of named pipes for communication between the main process and the auxiliary process, where each named pipe corresponds to one auxiliary process; the write-in unit 502 is configured to drive the main process to call the function WriteFile to write task data in the named pipe, and send the written task data to the corresponding auxiliary process; the reading unit 503 is configured to drive the auxiliary process to call a function ReadFile to read task data from a named pipeline; the execution and notification unit 504 is configured to drive the auxiliary process to perform corresponding task execution based on the task data, and after the task is completed, the auxiliary process calls the function AtExit to complete its exit, and sends data indicating that the task is completed and the auxiliary process has exited to the main process through the named pipe.
The embodiment of the invention also provides a multi-process management system which comprises a creation module, a writing module, a reading module and an execution and notification module.
The creating module is used for calling a CreateNamedPipe function in an API function of the Windows system to create a plurality of named pipelines for communication between the main process and the auxiliary process, and each named pipeline corresponds to one auxiliary process;
the write-in module is used for driving the main process to call the function WriteFile to write in the task data in the named pipeline and sending the written task data to the corresponding auxiliary process;
the reading module is used for driving the auxiliary process to call a function ReadFile to read task data from the named pipeline;
the execution and notification module is used for driving the auxiliary process to execute the corresponding task based on the task data, after the task is executed, the auxiliary process calls a function AtExit to complete self exit, and data used for indicating that the task is executed and the auxiliary process exits is sent to the main process through a named pipeline.
The multi-process management system of the embodiment of the invention ensures the normal operation of the application program under the operating condition of the multi-auxiliary process by creating the named pipeline for communication between the main process and the auxiliary process, then writing task data in the created named pipeline by the main process, sending the task data to the auxiliary process through the named pipeline, executing the corresponding task by the auxiliary process based on the task data, calling a function AtExit by the auxiliary process to finish the self exit after the task is executed, sending data for indicating that the task is executed and the auxiliary process is exited to the main process through the named pipeline, communicating between the auxiliary process and the main process through the created named pipeline, and simultaneously mastering the task execution state of the auxiliary process by the main process through the named pipeline.
The present invention is not limited to the above-described embodiments, and it will be apparent to those skilled in the art that various modifications and improvements can be made without departing from the principle of the present invention, and such modifications and improvements are also considered to be within the scope of the present invention. Those not described in detail in this specification are within the skill of the art.

Claims (9)

1. A multi-process management method is characterized by comprising the following steps:
calling a CreateNamedPipe function in an API function of the Windows system to create a plurality of named pipelines for communication between a main process and an auxiliary process, wherein each named pipeline corresponds to one auxiliary process, and the main process and the auxiliary process are processes of an application program running in the Windows system;
the main process calls a function WriteFile to write task data in a named pipeline and sends the written task data to a corresponding auxiliary process;
the auxiliary process calls a function ReadFile to read task data from the named pipeline;
the auxiliary process executes corresponding tasks based on the task data, calls a function AtExit to finish self exit after the tasks are executed, and sends data used for indicating that the tasks are executed and the auxiliary process exits to the main process through a named pipeline;
wherein, still include: writing an exception handling function for monitoring the auxiliary process, finishing the registration of the exception handling function in the Windows system, when the execution task of the auxiliary process is abnormal, informing the main process of the exception handling function by sending a log, and calling a function terminateProcess by the main process to terminate the operation of the auxiliary process;
the function Atexit is called to register the process exit function IpcExit, and the process exit function IpcExit informs the main process through a named pipeline.
2. A multi-process management method according to claim 1, characterized in that:
each auxiliary process correspondingly executes one task;
the name parameters are also required to be transmitted when the named pipeline is established;
the name parameter transmitted into the named pipeline is the name of the task to be executed by the auxiliary process corresponding to the named pipeline.
3. The multi-process management method of claim 1, wherein when named pipe creation is complete, for the host process:
calling a function ConnectNamedPipe to wait for the auxiliary process corresponding to the named pipeline to be connected;
the auxiliary process to be received finishes the connection with the main process through the named pipeline, and the auxiliary process is received and data for indicating the successful connection is sent to the main process through the named pipeline;
calling a function ReadFile to read data sent by the auxiliary process;
and calling a function WriteFile to write task data in the named pipeline and sending the written task data to a corresponding auxiliary process.
4. A multi-process management method according to claim 3, wherein, when the named pipe creation is completed, for the helper process:
calling a function CreateFile to connect the named pipeline and completing the connection with the main process;
sending data for indicating successful connection to the main process, and calling a function WaitNamedPipe to wait for the main process to correspond to the function;
and calling a function ReadFile to read the task data written by the main process from the named pipeline.
5. A multi-process management method according to claim 1, characterized in that: and if the main process does not receive data which is sent by the auxiliary process and used for indicating that the task is completely executed and the auxiliary process is quitted, the main process calls a function TerminateProcess to terminate the operation of the auxiliary process.
6. A multi-process management method according to claim 5, wherein: when the auxiliary process is terminated, the main process recreates the auxiliary process to re-execute the tasks that were executed before the terminated auxiliary process.
7. A storage medium having a computer program stored thereon, the computer program, when executed by a processor, performing the steps of:
calling a CreateNamedPipe function in an API function of the Windows system to create a plurality of named pipelines for communication between a main process and an auxiliary process, wherein each named pipeline corresponds to one auxiliary process, and the main process and the auxiliary process are processes of an application program running in the Windows system;
the main process calls a function WriteFile to write task data in a named pipeline and sends the written task data to a corresponding auxiliary process;
the auxiliary process calls a function ReadFile to read task data from the named pipeline;
the auxiliary process executes corresponding tasks based on the task data, calls a function AtExit to finish self exit after the tasks are executed, and sends data used for indicating that the tasks are executed and the auxiliary process exits to the main process through a named pipeline;
wherein, still include: writing an exception handling function for monitoring the auxiliary process, finishing the registration of the exception handling function in the Windows system, when the execution task of the auxiliary process is abnormal, informing the main process of the exception handling function by sending a log, and calling a function terminateProcess by the main process to terminate the operation of the auxiliary process;
the function Atexit is called to register the process exit function IpcExit, and the process exit function IpcExit informs the main process through a named pipeline.
8. An electronic device, comprising:
the system comprises a creating unit, a processing unit and a processing unit, wherein the creating unit is used for calling a CreateNamedPipe function in an API function of a Windows system to create a plurality of named pipelines for communication between a main process and an auxiliary process, each named pipeline corresponds to one auxiliary process, and the main process and the auxiliary process are processes of an application program running in the Windows system;
the write-in unit is used for driving the main process to call the function WriteFile to write in the task data in the named pipeline and sending the written task data to the corresponding auxiliary process;
the reading unit is used for driving the auxiliary process to call a function ReadFile to read task data from a named pipeline;
the execution and notification unit is used for driving the auxiliary process to execute the corresponding task based on the task data, calling a function AtExit by the auxiliary process to finish self exit after the task is executed, and sending data which is used for indicating that the task is executed and the auxiliary process exits to the main process through a named pipeline;
wherein, still include: writing an exception handling function for monitoring the auxiliary process, finishing the registration of the exception handling function in the Windows system, when the execution task of the auxiliary process is abnormal, informing the main process of the exception handling function by sending a log, and calling a function terminateProcess by the main process to terminate the operation of the auxiliary process;
the function Atexit is called to register the process exit function IpcExit, and the process exit function IpcExit informs the main process through a named pipeline.
9. A multiprocess management system, comprising:
the system comprises a creating module, a setting module and a processing module, wherein the creating module is used for calling a CreateNamedPipe function in an API function of a Windows system to create a plurality of named pipelines for communication between a main process and an auxiliary process, each named pipeline corresponds to one auxiliary process, and the main process and the auxiliary processes are processes of application programs running in the Windows system;
the write-in module is used for driving the main process to call the function WriteFile to write in the task data in the named pipeline and sending the written task data to the corresponding auxiliary process;
the reading module is used for driving the auxiliary process to call a function ReadFile to read task data from a named pipeline;
the execution and notification module is used for driving the auxiliary process to execute the corresponding task based on the task data, calling a function AtExit by the auxiliary process to finish self exit after the task is executed, and sending data which is used for indicating that the task is executed and the auxiliary process exits to the main process through a named pipeline;
wherein, still include: writing an exception handling function for monitoring the auxiliary process, finishing the registration of the exception handling function in the Windows system, when the execution task of the auxiliary process is abnormal, informing the main process of the exception handling function by sending a log, and calling a function terminateProcess by the main process to terminate the operation of the auxiliary process;
the function Atexit is called to register the process exit function IpcExit, and the process exit function IpcExit informs the main process through a named pipeline.
CN201810746906.6A 2018-07-09 2018-07-09 Multi-process management method, storage medium, electronic device and system Active CN109062686B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810746906.6A CN109062686B (en) 2018-07-09 2018-07-09 Multi-process management method, storage medium, electronic device and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810746906.6A CN109062686B (en) 2018-07-09 2018-07-09 Multi-process management method, storage medium, electronic device and system

Publications (2)

Publication Number Publication Date
CN109062686A CN109062686A (en) 2018-12-21
CN109062686B true CN109062686B (en) 2021-04-23

Family

ID=64819739

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810746906.6A Active CN109062686B (en) 2018-07-09 2018-07-09 Multi-process management method, storage medium, electronic device and system

Country Status (1)

Country Link
CN (1) CN109062686B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111147126B (en) * 2019-12-26 2021-11-23 中国人民解放军空军勤务学院 Beidou satellite short message communication data unpacking transmission method
CN113326139A (en) * 2021-06-28 2021-08-31 上海商汤科技开发有限公司 Task processing method, device, equipment and storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102355429A (en) * 2011-08-12 2012-02-15 北京思创银联科技股份有限公司 Pipeline-based inter-process message communication method
CN102801961A (en) * 2012-08-21 2012-11-28 北京捷成世纪科技股份有限公司 Multiprocess-based audio/video data processing method and system
CN107526645A (en) * 2017-09-06 2017-12-29 武汉斗鱼网络科技有限公司 A kind of communication optimization method and system

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102355429A (en) * 2011-08-12 2012-02-15 北京思创银联科技股份有限公司 Pipeline-based inter-process message communication method
CN102801961A (en) * 2012-08-21 2012-11-28 北京捷成世纪科技股份有限公司 Multiprocess-based audio/video data processing method and system
CN107526645A (en) * 2017-09-06 2017-12-29 武汉斗鱼网络科技有限公司 A kind of communication optimization method and system

Also Published As

Publication number Publication date
CN109062686A (en) 2018-12-21

Similar Documents

Publication Publication Date Title
CN100435101C (en) Apparatus and method for maintaining resource integrity in a software environment
KR100537813B1 (en) Emulation coprocessor
US8104043B2 (en) System and method for dynamic cooperative distributed execution of computer tasks without a centralized controller
US7406699B2 (en) Enhanced runtime hosting
US6308318B2 (en) Method and apparatus for handling asynchronous exceptions in a dynamic translation system
US7516361B2 (en) Method for automatic checkpoint of system and application software
US6886081B2 (en) Method and tool for determining ownership of a multiple owner lock in multithreading environments
US7669078B2 (en) Method and apparatus for debugging a program on a limited resource processor
US20120117423A1 (en) Fault tolerance in distributed systems
US7624309B2 (en) Automated client recovery and service ticketing
CA2904253C (en) Computer system using in-service software upgrade
CN103620561A (en) N-way runtime interoperative debugging
US8453013B1 (en) System-hang recovery mechanisms for distributed systems
CN109062686B (en) Multi-process management method, storage medium, electronic device and system
CN114168222B (en) Method and device for acquiring time consumption during starting, terminal equipment and storage medium
US7865883B1 (en) Parallel and asynchronous debugger and debugging method for multi-threaded programs
JPH07105023A (en) Method and apparatus for detection of spurious interrupt at inside of data processing system
US10002007B2 (en) Operating system (OS) independent device drivers
US20080077925A1 (en) Fault Tolerant System for Execution of Parallel Jobs
CN114816662A (en) Container arrangement method and system applied to Kubernetes
CN110515849B (en) Breakpoint debugging method, device, system, equipment and storage medium
US20090217290A1 (en) Method and System for Task Switching with Inline Execution
US8327378B1 (en) Method for gracefully stopping a multi-threaded application
CN111563000A (en) File generation method, intelligent terminal and storage medium
US20030212736A1 (en) System and method for activating and pausing a component

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
GR01 Patent grant
GR01 Patent grant