Specific embodiment
Below in conjunction with attached drawing in the embodiment of the present invention, technical solution in the embodiment of the present invention carries out clear, complete
Ground description, it is clear that described embodiments are only a part of the embodiments of the present invention, instead of all the embodiments.Usually exist
The component of the embodiment of the present invention described and illustrated in attached drawing can be arranged and be designed with a variety of different configurations herein.Cause
This, is not intended to limit claimed invention to the detailed description of the embodiment of the present invention provided in the accompanying drawings below
Range, but it is merely representative of selected embodiment of the invention.Based on the embodiment of the present invention, those skilled in the art are not doing
Every other embodiment obtained under the premise of creative work out, shall fall within the protection scope of the present invention.
It should also be noted that similar label and letter indicate similar terms in following attached drawing, therefore, once a certain Xiang Yi
It is defined in a attached drawing, does not then need that it is further defined and explained in subsequent attached drawing.Meanwhile of the invention
In description, term " first ", " second " etc. are only used for distinguishing description, are not understood to indicate or imply relative importance.
The method of interprocess communication provided in an embodiment of the present invention can be run in electronic equipment 100 shown in FIG. 1.Institute
Stating electronic equipment 100 can be user terminal or server.Further, the server can be network server, number
According to library server etc..The user terminal can be PC (personal computer, PC), tablet computer, intelligent hand
Machine, personal digital assistant (personal digital assistant, PDA), mobile unit, wearable device etc..
As shown in Figure 1, being the block diagram of electronic equipment 100.The electronic equipment 100 includes memory 101, processing
Device 102 and network module 103.
Memory 101 can be used for storing software program and module, such as the side of the interprocess communication in the embodiment of the present invention
Method and the corresponding program instruction/module of device, processor 102 by the software program that is stored in memory 101 of operation and
Module, thereby executing various function application and data processing, the i.e. method of interprocess communication in the realization embodiment of the present invention.
Memory 101 may include high speed random access memory, may also include nonvolatile memory, as one or more magnetic storage fills
It sets, flash memory or other non-volatile solid state memories.Further, the software program and module in above-mentioned memory 101
It may also include that operating system 121 and service module 122.Wherein operating system 121, may be, for example, LINUX, UNIX,
WINDOWS may include various for management system task (such as memory management, storage equipment control, power management etc.)
Component software and/or driving, and can mutually be communicated with various hardware or component software, to provide the operation of other software component
Environment.Service module 122 operates on the basis of operating system 121, and is come from by the network service of operating system 121 monitoring
The request of network completes corresponding data processing according to request, and returns to processing result to client.That is, service mould
Block 122 is used to provide network service to client.
Network module 103 is for receiving and transmitting network signal.Above-mentioned network signal may include wireless signal or have
Line signal.
It is appreciated that structure shown in FIG. 1 is only to illustrate, the electronic equipment 100 may also include more than shown in Fig. 1
Perhaps less component or with the configuration different from shown in Fig. 1.Each component shown in Fig. 1 can use hardware, software
Or combinations thereof realize.
Referring to Fig. 2, Fig. 2 shows a kind of schematic diagrames of multi-process manager of the embodiment of the present invention.The embodiment of the present invention
The method and device of the interprocess communication of offer can be run in the multi-process manager.As shown in Fig. 2, the multi-process management
The entry program of device is responsible for receiving configuration file and executes order.It wherein, include number, the host process of subprocess in configuration file
Communication mode between each subprocess and the corresponding business logic processing mode of each subprocess respectively.The entry program will
The configuration file and execution order are sent to host process, and host process parses the execution order, if execution order is initiation command,
Host process creates corresponding each subprocess according to configuration file.After each subprocess creation, when entry program receives
When waiting task, send host process for waiting task, host process according to the communication mode between each subprocess,
Realize the communication between each subprocess, subprocess adjusts back corresponding business logic processing mode and handles waiting task.
The access of the interprocess communication realized under this mode, subprocess is very simple, it is only necessary to modify configuration file i.e.
Can, the complicated multi-process programming of concern is no longer needed to, and be also able to achieve more business scenarios, further due to service logic
Processing mode is not coupled with multi-process management, therefore can reduce the expense of system.
It is retouched in more detail below in conjunction with method and device of the attached drawing to the interprocess communication in the embodiment of the present invention
It states.
Fig. 3 shows a kind of flow chart of the method for interprocess communication of first embodiment of the invention offer, please refers to figure
3, the method for the interprocess communication is run in above-mentioned electronic equipment, this method comprises:
Step S210, host process create corresponding each subprocess, wherein in the configuration file according to configuration file
Number, the host process including the subprocess communication mode between each subprocess and each subprocess respectively
Corresponding business logic processing mode.
There are many kinds of the sources of the configuration file, for example, it may be being received by entry program and actively issuing host process;
It can also be obtained from entry program with host process periodic polling entry program;Can also the configuration file be pre-stored in
In some storage region, read from the storage region by host process.Certainly, it is not limited to aforesaid way, any master into
The embodiment of the available configuration file of journey, shall fall within the protection scope of the present invention.
The quantity of the subprocess that the number for the subprocess for including in configuration file can create according to actual needs determines.
For example, if currently three subprocess is needed to handle three waiting tasks, the number of the subprocess in configuration file at this time
It can be set to 3.
Certainly, the ratio subprocess actually required more one that the number of configuration file sub-process also can be set
A bit, so that host process is created that the subprocess of some redundancies, facilitates subsequent use according to the configuration file.
Communication mode between host process and subprocess includes but is not limited to: pipe method, message queue mode, common memory
At least one of mode and aspect.It is of course also possible to obstructed between host process and subprocess being arranged in configuration file
Letter.
For example, if indicating logical between host process and subprocess in configuration file with field communication modes
Communication modes=1 can be set in letter mode, indicates that the communication mode between host process and subprocess is pipeline side
Formula;Communication modes=2 is set, indicates that the communication mode between host process and subprocess is message queue mode;If
Communication modes=3 is set, indicates that the communication mode between host process and subprocess is common memory mode;Setting
Communication modes=4 indicates that the communication mode between host process and subprocess is aspect;Setting
Communication modes=0, indicate host process between subprocess between do not communicate.By reading word in the configuration file
Section communication modes determines the communication mode between host process and subprocess.
Further, if host process creates multiple subprocess, the communication mode between host process and each subprocess can
With identical, for example, the communication mode and host process of host process and subprocess 1 and the communication mode of subprocess 2 can be pipeline
Mode.
Certainly, the communication mode between host process and each subprocess can also be different.For example, host process host process and son into
The communication mode of journey 1 is pipe method, and the communication mode of host process and subprocess 2 is then message queue mode.
The corresponding business logic processing mode of each subprocess in configuration file can be the API provided by business side
(Application Programming Interface, application programming interface), subprocess can be by adjusting back by business
The API that just provides handles waiting task.
It is different there are many host process is also possible to according to the embodiment that configuration file creates corresponding each subprocess
Platform can have the embodiment of different creation subprocess, and different programming languages also has the implementation of different creation subprocess
Mode.Any host process belongs to protection model of the invention according to the embodiment that configuration file creates corresponding each subprocess
It encloses.
As a kind of specific embodiment, host process can call fork function to create subprocess.According to configuration text
The number of part sub-process, the parameter of fork function is arranged, successively come determine creation subprocess number.
As another specific embodiment, if host process creates the mistake of corresponding each subprocess according to configuration file
Journey is write using PHP programming language, then host process can call pcntl_fork () function to create subprocess, specifically
Implementation details are not described herein again.
A specific example is named step S210 to be described in detail.
Assuming that configuration file includes:
(1) number of subprocess: 3.
(2) communication mode of host process and subprocess 1 are as follows: mode 1;The communication mode of host process and subprocess 2 are as follows: mode
2;The communication mode of host process and subprocess 3 are as follows: mode 3.
(3) the corresponding business logic processing mode of subprocess 1 are as follows: business logic processing mode 1;The corresponding industry of subprocess 2
Business logical process mode are as follows: business logic processing mode 2;The corresponding business logic processing mode of subprocess 3 are as follows: at service logic
Reason mode 3.
After host process receives the configuration file, create corresponding 3 subprocess, and be arranged its respectively with 3 subprocess
Between the corresponding business logic processing mode of communication mode and each subprocess.
Step S220, host process are realized and each subprocess according to the communication mode between each subprocess
Between communication.
As an implementation, host process receives waiting task, respectively basis and the communication party between each subprocess
The waiting task is sent each subprocess by formula, so that each subprocess receives described to be processed
It is engaged in and the corresponding business logic processing mode of each subprocess is called to be handled.
Continue to be illustrated with above-mentioned example, if host process reception waiting task 1, waiting task 2 and to be processed
Business 3.Waiting task 1 is sent to subprocess 1 and handles host process by pass-through mode 1 respectively, and pass-through mode 2 is by waiting task 2
It is sent to the processing of subprocess 2, waiting task 3 is sent to subprocess 3 and handled by pass-through mode 3.Subprocess 1 adjusts back corresponding industry
Logical process mode 1 of being engaged in handles waiting task 1, and subprocess 2 adjusts back corresponding business logic processing mode 2 and handles to be processed
Business 2, subprocess 3 adjusts back corresponding business logic processing mode 3 and handles waiting task 3, when each subprocess is disposed,
Whole process terminates.
Step S220 is illustrated with two kinds of specific embodiments below.
As a kind of specific embodiment, if the communication mode of the host process and the subprocess is pipe method,
The corresponding data of the waiting task are written into pipeline for host process, and subprocess reads described to be processed from the pipeline
It is engaged in corresponding data, and the corresponding business logic processing mode of the subprocess is called to handle the corresponding number of the waiting task
According to.
Wherein, the corresponding data of the waiting task may is that the number order for including in waiting task, and executing should
Business datum needed for waiting task, parameter or metadata etc..
It calls pipe () function to create a pipeline in kernel referring to Fig. 4, host process can first pass through, works as host process
When receiving waiting task, toward the corresponding data of the tail portion of pipeline write-in waiting task, head of the subprogram from the pipeline
Portion reads the corresponding data of the waiting task, and call the corresponding business logic processing mode of the subprocess handle it is described to
The corresponding data of processing task.If in the process, subprocess exits extremely, then the subprocess can be hung up by host process.
As another specific embodiment, if the communication mode of the host process and the subprocess is message queue
The corresponding message of the waiting task is written into message queue for mode, the host process so that the subprocess successively from
The corresponding message of the waiting task is read in the message queue, and calls the corresponding business logic processing of the subprocess
Mode handles the message read, until the corresponding message of all waiting tasks in the message queue is all handled
It finishes.
Wherein, the corresponding message of the waiting task may is that is parsed and generated by waiting task some disappears
Breath, the corresponding message of each waiting task can have a specific type of message, and subprocess is according to the waiting task pair of reading
The type of message and content answered call the corresponding business logic processing mode of subprocess to handle.
Referring to Fig. 5, host process can call msgget function to create a message queue in kernel in advance.When it is main into
When journey receives waiting task, the corresponding message of 3 waiting tasks is generated according to the waiting task.Host process is called
The corresponding message of 3 waiting tasks is written into the message queue for msgsnd function, it is assumed that the sequence of write-in is message 3, disappears
Cease 2, message 1.
Subprocess can be corresponding by calling msgrcv function successively to read 3 waiting tasks from the message queue
Message, the sequence of reading may is that message 3, message 2, message 1.
Certainly, the sequence for reading the corresponding message of waiting task can not also be according to the sequence of write-in, can be according to finger
Fixed sequence is read out, for example, according to: message 1, message 2, the sequence of message 3 are read;Can also be according to: message 1 disappears
The sequence of 3, message 2 is ceased to read.
The corresponding message of subprocess one waiting task of every reading, calls its corresponding business logic processing mode to carry out
Processing.After this 3 message in message queue are all disposed, subprocess terminates.If in the process, subprocess moves back extremely
Out, then the subprocess can be hung up by host process.
Further, described if not communicated between the host process and the subprocess as another specific embodiment
Method further include: the subprocess calls corresponding business logic processing mode to handle the waiting task.
Specifically, if host process is configured between host process and subprocess not communicate from what is read in configuration file, when
When receiving waiting task, host process only need to send subprocess for waiting task, be called by subprocess corresponding
Business logic processing mode has handled waiting task.If waiting task is multiple, subprocess recursive call correspondence
Business logic processing mode handle multiple waiting tasks respectively.
As a kind of specific embodiment, host process and subprocess in the present embodiment be all made of PHP programming language into
Journey programming can further save memory, and reduce the expense of system since its bottom layer realization code is C language.
The method of interprocess communication provided in an embodiment of the present invention creates corresponding by host process according to configuration file
Each subprocess, wherein in the configuration file including the number of subprocess, the host process respectively with each subprocess
Between communication mode and the corresponding business logic processing mode of each subprocess, and according between each subprocess
Communication mode, realize the communication between each subprocess, present solution provides the universal method of a set of interprocess communication,
So that business logic processing mode is no longer coupled with the communication between process, realize need to only modify configuration file can be realized son into
The access of journey no longer needs to the complicated multi-process programming of concern, is also able to achieve more business scenarios, and reduce opening for system
Pin.
Fig. 6 shows a kind of flow chart of the method for interprocess communication of second embodiment of the invention offer, please refers to figure
6, the method for the interprocess communication is run in above-mentioned electronic equipment, this method comprises:
Step S310, the acquired exectorial type of host process judgement.
It obtains there are many exectorial modes, for example, host process periodically can ask whether to hold to entry program
Line command, if so, then actively getting the execution order from entry program;External transmission can also be received by entry program
Execution order when, active transmission is to host process.Host process is by parsing the execution order, to determine the operation of next step.
Wherein, exectorial type includes but is not limited to cease and desist order, cease and desist order and reset command.
If the execution order executes step S320 to cease and desist order;If the execution order is reset command, step is executed
Rapid S330;If the execution order executes step S340 to cease and desist order.
Step S320, the host process exit, and each subprocess has executed currently pending task backed off after random.
After each subprocess has executed currently pending task backed off after random, entire EP (end of program).
Step S330, the host process execute described in cease and desist order after corresponding operation, it is corresponding to execute the initiation command
Operation.
Specifically, being that host process exits first, each subprocess has executed currently if execution order is reset command
Waiting task backed off after random.After each subprocess has executed currently pending task backed off after random, in order to which the host process can be resided
From the background, using host process as finger daemon, host process creates corresponding each subprocess according to configuration file, and according to it is each
Communication mode between a subprocess realizes the communication between each subprocess.
Step S340, host process create corresponding each subprocess, wherein in the configuration file according to configuration file
Number, the host process including the subprocess communication mode between each subprocess and each subprocess respectively
Corresponding business logic processing mode.
Step S350, the host process are realized and each son according to the communication mode between each subprocess
Communication between process.
After it is initiation command that host process, which parses the execution order, using host process as finger daemon, B simultaneously executes step
S340 to step S350.Wherein, the step S210 in the embodiment of step S340 to step S350 and a upper embodiment is extremely walked
The embodiment of rapid S220 is identical, and details are not described herein again.
The method of interprocess communication provided in an embodiment of the present invention creates corresponding by host process according to configuration file
Each subprocess, wherein in the configuration file including the number of subprocess, the host process respectively with each subprocess
Between communication mode and the corresponding business logic processing mode of each subprocess, and according between each subprocess
Communication mode, realize the communication between each subprocess, present solution provides the universal method of a set of interprocess communication,
So that business logic processing mode is no longer coupled with the communication between process, realize need to only modify configuration file can be realized son into
The access of journey no longer needs to the complicated multi-process programming of concern, is also able to achieve more business scenarios, and reduce opening for system
Pin.
Referring to Fig. 7, being the functional module signal of the device 400 for the interprocess communication that third embodiment of the invention provides
Figure.The device 400 of the interprocess communication includes creation module 410, communication module 420.
Creation module 410, for creating corresponding each subprocess, wherein in the configuration file according to configuration file
The communication mode between each subprocess and each subprocess are corresponding respectively for number, host process including subprocess
Business logic processing mode.
Communication module 420 is realized and each subprocess for basis and the communication mode between each subprocess
Between communication.
As an implementation, described device further includes receiving module 430, the receiving module 430 for receive to
Processing task;The communication module 420 will be described specifically for basis respectively and the communication mode between each subprocess
Waiting task is sent to each subprocess, so that each subprocess receives the waiting task and calls each
The corresponding business logic processing mode of a subprocess is handled.
As an implementation, the communication mode include: pipe method, message queue mode, common memory mode,
And at least one of aspect.
As an implementation, described logical if the communication mode of the host process and the subprocess is pipe method
Module 420 is believed, specifically for the corresponding data of the waiting task are written into pipeline, so that the subprocess is from described
The corresponding data of the waiting task are read in pipeline, and the corresponding business logic processing mode of the subprocess is called to handle
The corresponding data of the waiting task.
As an implementation, if the communication mode of the host process and the subprocess is message queue mode, institute
Communication module 420 is stated, specifically for the corresponding message of the waiting task is written into message queue, so that the subprocess
The corresponding message of the waiting task is successively read from the message queue, and the corresponding business of the subprocess is called to patrol
Volume processing mode handles the message read, until the corresponding message of all waiting tasks in the message queue is complete
Portion is disposed.
As an implementation, if not communicating between the host process and the subprocess, described device includes processing mould
Block 440 calls corresponding business logic processing mode to handle the waiting task for the subprocess.
As an implementation, described device further includes obtaining module 450, executes order for obtaining;The creation
Module 410, specifically for the acquired exectorial type of host process judgement;If the execution order is to start to order
It enables, the host process creates corresponding each subprocess according to configuration file.
As an implementation, described device further includes exiting module 460, acquired in judging in the host process
Exectorial type after, if execution order is ceases and desist order, the host process is exited, and each subprocess is held
Currently pending task backed off after random is gone.
As an implementation, described device further includes restarting module 470, acquired in judging in the host process
Exectorial type after, if execution order is reset command, the host process execute described in cease and desist order correspondence
Operation after, execute the corresponding operation of the initiation command.
Above each module can be by software code realization, at this point, above-mentioned each module can be stored in depositing for electronic equipment
In reservoir 101.Above each module can equally be realized by hardware such as IC chip.
Fourth embodiment of the invention provides a kind of electronic equipment, and the electronic equipment includes memory and processor, institute
State memory and be couple to the processor, the memory store instruction, when executed by the processor so that
The processor executes following operation:
Host process creates corresponding each subprocess according to configuration file, wherein includes subprocess in the configuration file
Number, the host process communication mode between each subprocess and the corresponding business of each subprocess respectively
Logical process mode;
The host process is realized logical between each subprocess according to the communication mode between each subprocess
Letter.
It should be noted that all the embodiments in this specification are described in a progressive manner, each embodiment weight
Point explanation is the difference from other embodiments, and the same or similar parts between the embodiments can be referred to each other.
The technical effect of the device of interprocess communication provided by the embodiment of the present invention, realization principle and generation and aforementioned
Embodiment of the method is identical, and to briefly describe, Installation practice part does not refer to place, can refer to corresponding in preceding method embodiment
Content.
In several embodiments provided herein, it should be understood that disclosed device and method can also pass through
Other modes are realized.The apparatus embodiments described above are merely exemplary, for example, flow chart and block diagram in attached drawing
Show the device of multiple embodiments according to the present invention, the architectural framework in the cards of method and computer program product,
Function and operation.In this regard, each box in flowchart or block diagram can represent the one of a module, section or code
Part, a part of the module, section or code, which includes that one or more is for implementing the specified logical function, to be held
Row instruction.It should also be noted that function marked in the box can also be to be different from some implementations as replacement
The sequence marked in attached drawing occurs.For example, two continuous boxes can actually be basically executed in parallel, they are sometimes
It can execute in the opposite order, this depends on the function involved.It is also noted that every in block diagram and or flow chart
The combination of box in a box and block diagram and or flow chart can use the dedicated base for executing defined function or movement
It realizes, or can realize using a combination of dedicated hardware and computer instructions in the system of hardware.
In addition, each functional module in each embodiment of the present invention can integrate one independent portion of formation together
Point, it is also possible to modules individualism, an independent part can also be integrated to form with two or more modules.
It, can be with if the function is realized and when sold or used as an independent product in the form of software function module
It is stored in a computer readable storage medium.Based on this understanding, technical solution of the present invention is substantially in other words
The part of the part that contributes to existing technology or the technical solution can be embodied in the form of software products, the meter
Calculation machine software product is stored in a storage medium, including some instructions are used so that a computer equipment (can be a
People's computer, server or network equipment etc.) it performs all or part of the steps of the method described in the various embodiments of the present invention.
And storage medium above-mentioned includes: USB flash disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), arbitrary access
The various media that can store program code such as memory (RAM, Random Access Memory), magnetic or disk.It needs
It is noted that herein, such as first and the relational terms of third or the like be used merely to an entity or operation
It is distinguished with another entity or operation, without necessarily requiring or implying between these entities or operation, there are any this
Actual relationship or sequence.Moreover, the terms "include", "comprise" or its any other variant are intended to nonexcludability
It include so that the process, method, article or equipment for including a series of elements not only includes those elements, but also to wrap
Include other elements that are not explicitly listed, or further include for this process, method, article or equipment intrinsic want
Element.In the absence of more restrictions, the element limited by sentence "including a ...", it is not excluded that including described want
There is also other identical elements in the process, method, article or equipment of element.
The foregoing is only a preferred embodiment of the present invention, is not intended to restrict the invention, for the skill of this field
For art personnel, the invention may be variously modified and varied.All within the spirits and principles of the present invention, made any to repair
Change, equivalent replacement, improvement etc., should all be included in the protection scope of the present invention.It should also be noted that similar label and letter exist
Similar terms are indicated in following attached drawing, therefore, once being defined in a certain Xiang Yi attached drawing, are then not required in subsequent attached drawing
It is further defined and explained.
The above description is merely a specific embodiment, but scope of protection of the present invention is not limited thereto, any
Those familiar with the art in the technical scope disclosed by the present invention, can easily think of the change or the replacement, and should all contain
Lid is within protection scope of the present invention.Therefore, protection scope of the present invention should be subject to the protection scope in claims.