Summary of the invention
Process management method and management of process device are provided in the embodiment of the present invention, with solve master in the prior art intoCheng Buneng effectively distinguishes each subprocess, leads to the problem that the efficiency of management is low.
In order to solve the above-mentioned technical problem, the embodiment of the invention discloses following technical solutions:
On the one hand, a kind of process management method is provided, the method is used for management of the host process to subprocess, the sideMethod includes:
Query procedure id command is written in the shell-command performed by the primary target subprocess of host process, so that institutePrimary target subprocess is stated when executing the shell-command, the process ID of the primary target subprocess is sent to host process;
Host process obtains the level-one that the primary target subprocess is sent after starting the primary target subprocessThe process ID of target subprocess;
All progress informations that the user includes are inquired according to the corresponding user name of user for starting the host process;
All progress informations that the user includes are analyzed according to the process ID of the primary target subprocess, withObtain the process ID of the subprocess for all ranks that the primary target subprocess includes.
Optionally, query procedure ID is written in the shell-command performed by the primary target subprocess of host processOrder includes: that the inquiry is written in the initial position of the shell-command performed by the primary target subprocess of the host processProcess id command.
Optionally, all progress informations that the user includes are carried out according to the process ID of the primary target subprocessAnalysis, to obtain the process ID of the subprocess for all ranks that the primary target subprocess includes, comprising:
It is successively retrieved from the process ID of the primary target subprocess, until obtaining the primary target subprocess packetThe process ID of the subprocess of all ranks contained retrieves described in retrieval according to the process ID of the subprocess of current levelThe process ID of the other subprocess of the next stage of the subprocess of current level.
Optionally, the process management method further include:
According to the process ID of the primary target subprocess of acquisition, and the primary target subprocess obtained includesAll ranks subprocess process ID, delete the institute that the primary target subprocess and the primary target subprocess includeThere is the subprocess of rank.
On the other hand, a kind of management of process device is provided, the system is used for management of the host process to subprocess, describedManagement of process device includes:
Writing unit, for query procedure to be written in shell-command performed by the primary target subprocess in host processId command, so that the primary target subprocess sends primary target when executing the shell-command, to host processThe process ID of process;
First obtains unit, for obtaining the primary target when host process is after starting the primary target subprocessThe process ID for the primary target subprocess that subprocess is sent;
Query unit, for inquiring the institute that the user includes according to the corresponding user name of user for starting the host processThere is progress information;
Second obtaining unit, for what is inquired according to the process ID of the primary target subprocess to the query unitThe progress information that the user includes is analyzed, to obtain the subprocess for all ranks that the primary target subprocess includesProcess ID.
Optionally, said write unit includes: rising for the shell-command performed by the primary target subprocess of host processThe query procedure id command is written in beginning position.
Optionally, second obtaining unit includes:
It is successively retrieved from the process ID of the primary target subprocess, until obtaining the primary target subprocess packetThe process ID of the subprocess of all ranks contained retrieves described in retrieval according to the process ID of the subprocess of current levelThe process ID of the other subprocess of the next stage of the subprocess of current level.
Optionally, the management of process device further include:
Delete unit, the process ID of the primary target subprocess for obtaining according to first obtains unit, Yi JiThe process ID of the subprocess for all ranks that the primary target subprocess that two obtaining units obtain includes, deletes the level-oneThe subprocess for all ranks that target subprocess and the primary target subprocess include.
By above technical scheme as it can be seen that process management method provided by the invention and management of process device, first byQuery procedure id command is written in shell-command performed by the primary target subprocess of host process, to obtain the level-one meshThe process ID for marking subprocess, further according to the corresponding user name of user for starting the host process inquire that the user includes it is allProgress information, and all progress informations that the user includes are divided according to the process ID of the primary target subprocessAnalysis, to obtain the process ID of the subprocess for all ranks that the primary target subprocess includes.Technical solution of the present invention energyHost process is enough set to obtain the process ID of the subprocess of all ranks, so that host process be allowed to carry out for specific target subprocessMonitoring and management, such as certain subprocess for expending resource are deleted, to prevent these subprocess from carrying out for a long time to system resourceIt is wasted caused by occupancy.
Specific embodiment
The embodiment of process management method of the present invention is illustrated first, as shown in Figure 1, being management of process side of the present inventionThe flow diagram of one embodiment that method provides, the embodiment include the following steps:
Step 101: query procedure ID life being written in the shell-command performed by the primary target subprocess of host processIt enables, so that the primary target subprocess sends the primary target subprocess when executing the shell-command, to host processProcess ID.
With reference to background technique, the subprocess started in host process is known as level-one subprocess, generally starts in host processMore than one subprocess specifies a target subprocess for convenience.Host process can obtain the key of the target subprocessWord information or title, to start to the target subprocess.
For example, the code of the querying command are as follows:
Echo processId=$ $;
Wherein, processId is the variable parameter name of the process ID of the subprocess of inquiry, correspondingly, obtaining in a step 102It is also obtained according to this variable parameter name when obtaining the process ID of the subprocess.
The code is put into the shell-command of the primary target subprocess or the script command of .sh type, when described oneWhen grade target subprocess executes the script of the shell-command or .sh type, just can be returned to host process target level-one intoThe process ID of journey.
Shell-command is to execute order to have actually entered shell platform when user logs in, it follows certain grammer,The order of input is explained and is transmitted to system.Shell-command can be realized the real-time acquisition of data file, read text in timeThe newly generated content of part.Any one shell-command is write in the file of .sh ending, that is, to form .sh script .sh scriptIt is the script file of UNIX/LINUX operating system.
Step 102: host process obtains what the primary target subprocess was sent after starting the primary target subprocessThe process ID of the primary target subprocess.
Subprocess is after executing the shell-command, and the data content returned to host process may be relatively more, with reference to step101 associated description can obtain the process ID of the subprocess according to the variable parameter name in the code of querying command before,For example, the correlative code got are as follows:
ProcessId=4007;
The process ID for indicating the primary target subprocess is 4007.
Step 103: according to the corresponding user name of user for starting the host process inquire that the user includes it is all intoJourney information.
In the application, all progress informations of user's "comprising" refer to that the user directly or indirectly starts at different levelsThe information of subprocess, the i.e. information of the process of all ranks under the user name.
The realization code of corresponding inquiry mode are as follows:
ps-ef|grep-v grep|grep^username;
Wherein, username is the corresponding user name of user for starting host process, in practical applications, alternatively at systemActual user name.This section of code is inputted in order line, can obtain the son of user name username all rank under one's nameProcess, wherein also including the relevant information of host process.
Step 104: all progress informations for including to the user according to the process ID of the primary target subprocess intoRow analysis, to obtain the process ID of the subprocess for all ranks that the primary target subprocess includes.
The corresponding query result of step 103 is the relevant information for all processes that user includes, including user startingThe process ID number of the subprocess for the different stage that multiple host processes and each host process include and some relevant description informations, becauseThis is more many and diverse, the process for the primary target subprocess for needing to obtain in process ID and step 102 by the host processID is searched, until finding out the process ID of the subprocess for all ranks that the primary target subprocess includes.
It in other embodiments of the invention, optionally, can also include step 105: according to the level-one mesh of acquisitionMark the process ID of subprocess, and the primary target subprocess all ranks that include obtained subprocess process ID,Delete the subprocess for all ranks that the primary target subprocess and the primary target subprocess include.
By above embodiments as it can be seen that process management method provided in an embodiment of the present invention, first by the one of host processQuery procedure id command is written in shell-command performed by grade target subprocess, to obtain the primary target subprocessProcess ID inquires all progress informations that the user includes further according to the corresponding user name of user for starting the host process,And all progress informations that the user includes are analyzed according to the process ID of the primary target subprocess, to obtainState the process ID of the subprocess for all ranks that primary target subprocess includes.Technical solution of the present invention can be such that host process obtainsThe process ID of the subprocess of all ranks is obtained, so that host process is allowed to be monitored and manage for specific target subprocess,Such as certain subprocess for expending resource are deleted, to prevent these subprocess wave caused by system resource progress long-time occupancyTake.
As shown in Figure 2 A, the flow diagram of another embodiment provided for process management method of the present invention, the implementationExample includes the following steps:
Step 201: institute is written in the initial position of the shell-command performed by the primary target subprocess of the host processState query procedure id command so that the primary target subprocess is when executing the shell-command, send to host process described inThe process ID of primary target subprocess.
For example, the code of the querying command are as follows:
Echo processId=$ $;
Wherein, processId is the variable parameter name of the process ID of the subprocess of inquiry, correspondingly, obtaining in step 202It is also obtained according to this variable parameter name when obtaining the process ID of the subprocess.
The code of the querying command is put into the initial position of shell-command, specifically can be, in the shell-command pairBefore the former first trip code for the code answered, new a line is inserted into as first trip, the code of the querying command is written in the first trip,It is the corresponding code schematic diagram of process of the query procedure ID, the shell-command is original in the figure such as shown in Fig. 2 BCode is replaced with dotted line.
Optionally, the code of the querying command is put into the command header of shell-command, it is specific it is also possible that at thisBefore the initial position of the corresponding code of shell-command, it is inserted into the code of the querying command, i.e., is put the code of the querying commandIt is the another of the corresponding code of process of the query procedure ID as shown in Figure 2 C in the first trip of the corresponding code of the shell-commandOne schematic diagram, original code of the shell-command is replaced with dotted line in the figure.
It is also more many and diverse since the data that the subprocess returns may be relatively more, described in the insertion of query procedure id commandThe initial position of shell-command is advantageous in that, can from the data that the level-one subprocess returns, in the first row data orThe corresponding ID of the level-one subprocess can be quickly found out in first few lines.
Step 202: host process obtains what the primary target subprocess was sent after starting the primary target subprocessThe process ID of the primary target subprocess.
A certain thread inside host process starts the target subprocess, obtains the input of the target subprocess, for readingThe data for taking the target subprocess to return, the content of the first row returned data is processId=process ID, can be obtained instituteState the process ID of primary target subprocess.
Step 203: according to the corresponding user name of user for starting the host process inquire that the user includes it is all intoJourney information.
Corresponding inquiry code are as follows:
ps-ef|grep-v grep|grep^username;
Wherein, username is the corresponding user name of user for starting host process, in practical applications, alternatively at systemActual user name.This section of code is inputted in order line, can obtain the son of user name username all rank under one's nameProcess also includes the relevant information of host process.
Step 204: successively being retrieved from the process ID of the primary target subprocess, until obtaining the primary targetThe process ID of the subprocess for all ranks that subprocess includes is examined in retrieval according to the process ID of the subprocess of current levelRope to the current level subprocess the other subprocess of next stage process ID.
Here it is as shown in Figure 2 D come the process for illustrating step 203 and step 204 with the example in a practical applicationThe schematic diagram of the corresponding inquiry code of step 203 and corresponding query result.
As shown in Figure 2 D, inquiry code corresponding with step 203 are as follows:
ps-ef|grep-v grep|grep^idcp;
Wherein idcp is the corresponding user name of user for starting host process.The inquiry knot listed below the inquiry codeIt include multirow data in fruit, every data line indicates the information of a process, and first row indicates to start the use of the user of the processName in an account book, i.e. idcp, second is classified as the process ID of the process, and third is classified as the other process of upper level of this process, remaining is classified asThe associated description information of this process.
As shown in Figure 2 D, the row where the information of host process is found first, since higher level's process of host process is to startThe user of the host process, i.e. idcp, user are system-level, process ID number default 1, thus find accordingly the process ID of host process=3915.In fact, host process is known that oneself ID number in a starting, can also directly according to the ID=3915 of host process andProcess ID=1 of user is quickly found out the row where host process.
According to process ID=3915 of host process, successively finding the corresponding ID number of several level-one subprocess is 4007,4021,4038,4050,4064, it is assumed that process ID=4007 of the target subprocess obtained in step 202, then further rootProcess ID=4010 of the next stage subprocess of the target subprocess are found according to process ID=4007 of the target subprocess, i.e.,For second level subprocess.The next of the second level subprocess further is found according to process ID=4010 of the second level subprocess laterProcess ID=4011 of grade subprocess, as three-level subprocess.Successively retrieved according to the method, until find target intoThe process ID of the subprocess for all ranks that journey (ID=4007) includes.
Step 205: according to the process ID of the primary target subprocess of acquisition, and the primary target obtainedThe process ID of the subprocess for all ranks that process includes deletes the primary target subprocess and the primary target subprocessThe subprocess for all ranks for including.
In some cases, some subprocess of host process can not may be exited normally due to various reasons, be caused under itGrade subprocess also can not can obtain the institute that the subprocess includes normally to out according to the method in step 201 to 204 at this timeHave the subprocess of rank, thus in host process Force Deletion or stop other sons of the subprocess and all ranks intoJourney.
By above embodiments as it can be seen that process management method provided in an embodiment of the present invention, first by the one of host processQuery procedure id command is written in the initial position of shell-command performed by grade target subprocess, to obtain the primary targetThe process ID of subprocess, further according to the corresponding user name of user for starting the host process inquire that the user includes it is all intoJourney information, and all progress informations that the user includes are analyzed according to the process ID of the primary target subprocess,To obtain the process ID of the subprocess for all ranks that the primary target subprocess includes step by step.Technical solution of the present invention energyHost process is enough set to obtain the process ID of the subprocess of all ranks, so that host process be allowed to carry out for specific target subprocessMonitoring and management, such as certain subprocess for expending resource are deleted, to prevent these subprocess from carrying out for a long time to system resourceIt is wasted caused by occupancy.
Corresponding with the embodiment of process management method of the present invention, this specification additionally provides corresponding management of process deviceEmbodiment.
For convenience of description, it describes to describe various units respectively with function when the management of process device of the application.WhenSo, the function of each unit can be realized in the same or multiple software and or hardware in carrying out the present invention.
Referring to Fig. 3, for the structural schematic diagram for the embodiment that management of process device of the present invention provides, the management of process deviceIt include: writing unit 301, first obtains unit 302, query unit 303 and the second obtaining unit 304.
Wherein, writing unit 301, for being written in shell-command performed by the primary target subprocess in host processQuery procedure id command, so that the primary target subprocess sends described one when executing the shell-command, to host processThe process ID of grade target subprocess.
First obtains unit 302, for obtaining the level-one mesh when host process is after starting the primary target subprocessMark the process ID for the primary target subprocess that subprocess is sent.
Query unit 303, for including according to the user for the starting the host process corresponding user name inquiry userAll progress informations.
Second obtaining unit 304, for being inquired according to the process ID of the primary target subprocess the query unitTo the user progress information that includes analyze, to obtain the son for all ranks that the primary target subprocess includesThe process ID of process.
Preferably, said write unit 301 includes:
The query procedure ID is written in the initial position of the shell-command performed by the primary target subprocess of host processOrder.
Preferably, second obtaining unit 304 includes:
It is successively retrieved from the process ID of the primary target subprocess, until obtaining the primary target subprocess packetThe process ID of the subprocess of all ranks contained retrieves described in retrieval according to the process ID of the subprocess of current levelThe process ID of the other subprocess of the next stage of the subprocess of current level.
Optionally, the management of process device further include:
Delete unit, the process ID of the primary target subprocess for obtaining according to first obtains unit, Yi JiThe process ID of the subprocess for all ranks that the primary target subprocess that two obtaining units obtain includes, deletes the level-oneThe subprocess for all ranks that target subprocess and the primary target subprocess include.
Management of process device in above-described embodiment, wherein modules unit executes the concrete mode and relevant of operationCode is described in detail in the embodiment of the method, and no detailed explanation will be given here, related placeIllustrate referring to the part of embodiment of the method.
By above embodiments as it can be seen that management of process device provided in an embodiment of the present invention, first by the one of host processQuery procedure id command is written in the initial position of shell-command performed by grade target subprocess, to obtain the primary targetThe process ID of subprocess, further according to the corresponding user name of user for starting the host process inquire that the user includes it is all intoJourney information, and all progress informations that the user includes are analyzed according to the process ID of the primary target subprocess,To obtain the process ID of the subprocess for all ranks that the primary target subprocess includes step by step.Technical solution of the present invention energyHost process is enough set to obtain the process ID of the subprocess of all ranks, so that host process be allowed to carry out for specific target subprocessMonitoring and management, such as certain subprocess for expending resource are deleted, to prevent these subprocess from carrying out for a long time to system resourceIt is wasted caused by occupancy.
The present invention can describe in the general context of computer-executable instructions executed by a computer, such as programModule.Generally, program module includes routines performing specific tasks or implementing specific abstract data types, programs, objects, groupPart, data structure etc..The present invention can also be practiced in a distributed computing environment, in these distributed computing environments, byTask is executed by the connected remote processing devices of communication network.In a distributed computing environment, program module can be withIn the local and remote computer storage media including storage equipment.
The above is only a specific embodiment of the invention, is made skilled artisans appreciate that or realizing this hairIt is bright.Various modifications to these embodiments will be apparent to one skilled in the art, as defined hereinGeneral Principle can be realized in other embodiments without departing from the spirit or scope of the present invention.Therefore, of the inventionIt is not intended to be limited to the embodiments shown herein, and is to fit to and the principles and novel features disclosed herein phase oneThe widest scope of cause.