Invention content
The embodiment of the present invention provides a kind of method, apparatus and equipment marking PHP processes using process filesystem, to
It solves the problems, such as existing in the prior art cannot effectively mark PHP processes.
On the one hand, an embodiment of the present invention provides a kind of methods marking PHP processes using process filesystem, including:
Token variable is written in environmental variance, static before program startup for the program for needing static tay
Before the program of label brings into operation, the environmental variance is read in current process environmental variance list, from the environmental variance
Token variable field in read program process mark, restart labeled program process;
For dynamically labeled program is needed, it is loaded into pre-set programming indicia code in a program, passes through loading
Programming indicia code opens the tab file of designated file name in agreement catalogue, the listed files that search program process has been opened
In the tab file link.
It is described that token variable is written in environmental variance before program startup in some optional embodiments, including:
Before program startup, the token variable of key assignments form is written by shell scripts;Or token variable is write on into week
In the project crontab files that phase property executes;Or token variable is write into corresponding system finger daemon systemd and is matched
It sets in file.
It is described to be loaded into pre-set programming indicia code in a program in some optional embodiments, including:
Programming indicia code is provided previously, described program marker code provides dynamically labeled application programming interface
At least one of API, including create label, delete label;
It is loaded into the described program marker code being provided previously in a program.
In some optional embodiments, the above method further includes:
When requiring to look up the label of program process, all program process for meeting setting condition are traversed, environment is read and becomes
File is measured, the program process mark being previously written is searched;
Traverse all program process for meeting setting condition, the specified text in the listed files that reading program process has been opened
The tab file of corresponding designated file name is found in the link of the tab file of part title by the link of reading.
In some optional embodiments, the above method further includes:
According to the listed files opened, file addressing offset operation is carried out to the file opened, finds tab file
Offset address.
The embodiment of the present invention also provides a kind of device marking program process using process filesystem, including:
Static tay module, for being written in environmental variance before program startup for the program for needing static tay
Token variable reads the environment in current process environmental variance list and becomes before being brought into operation by the program of static tay
Amount reads program process mark from the token variable field of the environmental variance, restarts labeled program process;
Dynamically labeled module, for for dynamically labeled program is needed, being loaded into pre-set program mark in a program
Remember code, open the tab file of designated file name in agreement catalogue by the programming indicia code of loading, search program into
The link of the tab file in the listed files that journey has been opened.
In some optional embodiments, the static tay module is specifically used for:
Before program startup, the token variable of key assignments form is written by shell scripts;Or token variable is write on into week
In the project crontab files that phase property executes;Or token variable is write into corresponding system finger daemon systemd and is matched
It sets in file.
In some optional embodiments, the dynamically labeled module is specifically used for:
Programming indicia code is provided previously, described program marker code provides dynamically labeled application programming interface
At least one of API, including create label, delete label;
It is loaded into the described program marker code being provided previously in a program.
In some optional embodiments, above-mentioned apparatus further includes:
Identifier acquisition module, for when requiring to look up the label of program process, traversing all journeys for meeting setting condition
Sequence process reads environment variable files, searches the program process mark being previously written;Traverse all programs for meeting setting condition
Process, the link of the tab file of the designated file name in the listed files that reading program process has been opened, passes through reading
The tab file of corresponding designated file name is found in link.
In some optional embodiments, the dynamically labeled module is additionally operable to:
According to the listed files opened, file addressing offset operation is carried out to the file opened, finds tab file
Offset address.
The embodiment of the present invention also provides a kind of host equipment, including:As above-mentioned utilization process filesystem marks program
The device of process.
Also a kind of computer storage media of the embodiment of the present invention, being stored with computer in the computer storage media can hold
Row instruction, the computer executable instructions are used to execute the above-mentioned method for marking program process using process filesystem.
Above-mentioned technical proposal has the advantages that:
Process can be identified in environmental variance before startup by being written token variable in a program before starting,
It realizes static tay, can also be realized through filename guide mark file, side by being loaded into programming indicia code in a program
Process being marked just, this method can easily be marked program process, the class that the process of being not only restricted to is supported
Type can also carry out significant notation for the process of no control group mark, not need daily record and be associated inquiry, not by daily record
Deletion and newer influence, versatile, it is convenient to search, and can identification effectively be marked to process.
Specific implementation mode
Following will be combined with the drawings in the embodiments of the present invention, and technical solution in the embodiment of the present invention carries out clear, complete
Site preparation describes, it is clear that described embodiments are only a part of the embodiments of the present invention, instead of all the embodiments.It is based on
Embodiment in the present invention, it is obtained by those of ordinary skill in the art without making creative efforts every other
Embodiment shall fall within the protection scope of the present invention.
In order to solve the problems, such as it is existing in the prior art effectively program process cannot be marked, the present invention implement
Example provides a kind of method marking program process using process filesystem, can mark program using procfs on linux
Process, the type that the process of being not only restricted to is supported is versatile, and it is convenient to search, and can identification effectively be marked to process.
In many class Unix computer systems, process filesystem (the proc file system, procfs) packet
Containing a pseudo file system, which is the file system of dynamic generation when starting, and progress information is accessed for passing through kernel.This
A file system is usually mounted to/proc catalogues, as soon as since/proc is not a real file system, it is also not take up
Memory space only occupies limited memory.The present invention is marked program process using process filesystem, leads to below
Specific embodiment is crossed to be described in detail.
It is provided in an embodiment of the present invention using process filesystem mark program process method, flow as shown in Figure 1,
Include the following steps:
Step S101:For the program for needing static tay, before program startup, write-in label becomes in environmental variance
Amount.
Static tay can be with the completion of convenience and high-efficiency, and the influence for being not easily susceptible to program itself.Before program startup, pass through
The token variable of key assignments form is written in shell scripts, or label script is write on the project periodically executed
(crontab) in file, or token variable is write into corresponding system finger daemon (Systemdaemon, systemd) and is matched
It sets in file.
Wherein, the token variable that key assignments form is written by shell scripts, can be by the bash scripts of key-value form
It is written in environmental variance.
Such as:Before program startup, using the bash scripts of VAR_SOMEKEY=SOMEVALUE forms, or directly write
In crontab, process is marked.The variable that there is VAR_SOMEKEY in environmental variance, later again in this environment
Middle to start program to be marked, then the program to be marked being just activated can also inherit environmental variance;
It is the Unixshell for removing from office slave (GNU) and planning to write that Bash (Bourne-Again Shell), which is one,.crontab
Order is common among the operating system of Unix and class Unix, for the instruction being periodically performed to be arranged.The order is from standard
Input equipment reads instruction, and is deposited in " crontab " file, for reading and executing later.
Step S102:Before being brought into operation by the program of static tay, the read loop in current process environmental variance list
Border variable reads program process mark from the token variable field of environmental variance, restarts labeled program process.
Before labeled program brings into operation, you can in list/proc/ of current process environmental variance<pid>/environ
In read relevant environmental variance, program process mark, wherein identification parameter are read from the token variable field of environmental variance<
pid>Replace with the mark pid of process.Such as:It replaces<pid>Pid be 355 if, shaped like/proc/355/environ
File can take result above-mentioned.Then restart labeled program process.
Step S103:For dynamically labeled program is needed, it is loaded into pre-set programming indicia code in a program.
For needing to carry out dynamically labeled program, programming indicia code is provided previously, described program marker code provides
At least one of dynamically labeled application programming interface (API), including create label, delete label;It carries in a program
Enter the programming indicia code being provided previously.Programming indicia code can be PHP marking classes.
That is, for needing dynamically labeled program, a PHP class is provided, needs the program marked by such load
Enter, it is such that some dynamically labeled API are provided, it such as creates, delete label.
Step S104:The tab file of designated file name in agreement catalogue is opened by the programming indicia code of loading,
The link of the tab file in the listed files that search program process has been opened.
When needing that application program is marked, the catalogue that a business is of little use can be arranged, and by mark above-mentioned
Note code (module) opens the file of the specific names in this catalogue, you can in/proc/<pid>This document is found under/fd/
Link ,/tmp/nonuseddirformark/abc_somevalue this link such as can be opened.
File addressing offset operation can be carried out to the file opened, find label according to the listed files opened
The offset address of file.Mark of correlation file can be found according to the information of opened file in the listed files opened
Offset address, such as:Can open file be subjected to file addressing offset operation, be addressed to a specified address, i.e.,
For the offset address of tab file.
Here from store content in the prior art elsewhere unlike, the specific names that are proposed in the application
File, is only effectively its filename, and file itself can be not present in respective directories, need not also be write to file itself
Enter any content.It therefore, there is no need to obtain file itself, it is only necessary to obtain title, easy operation reduces storage number
According to amount, volume of transmitted data is decreased.
It is alternatively possible to which open file is carried out file addressing offset operation, it is addressed to a specified address.It can be with
According to the fileinfo opened, the offset address of mark of correlation file is found.
Program process is marked in the above method, the mode that static tay both may be used, and dynamic can also be used to mark
The mode of note is marked, or both program process and combines.It can effectively mark program process, and can
Ensure label and the correspondence of process.It can be PHP processes to need labeled process, can also be other program process.
It is provided in an embodiment of the present invention using process filesystem mark program process method, further include obtain program into
The process of journey label, flow is as shown in Fig. 2, include the following steps:
Step S201:When requiring to look up the label of program process, all program process for meeting setting condition are traversed.
Because label information is written in environmental variance when static tay, when therefore, it is necessary to search mark of correlation, traversal
Program process obtains the mark of correlation variable information in environmental variance, carrys out search program Processes Tag.
Such as:Meet the program process of setting condition, can be some labeling process for specifying some user, then set item
Part is that process belongs to this user.
Step S202:Environment variable files are read, the program process mark being previously written is searched.
Relative program process is traversed, its environmental variance (environ) is read, it can be before reading startup in environ
The static tay of write-in.
Such as:If program has used the VAR_SOMEKEY=SOMEVALUE forms described in aforementioned static labeling process
Bash script markups, then it can be seen that the content shaped like VAR_SOMEKEY=SOMEVALUE.
In another example:If program has used the crontab modes described in aforementioned static labeling process to be marked, can
Only to find related content in crontab.
Step S203:Traverse all program process for meeting setting condition.
Because when dynamically labeled, being loaded with programming indicia code in a program, therefore, it can traverse and meet setting condition
Relative program process reads the link in its fd catalogue, to obtain the link of tab file.Wherein, fd catalogues contain process
The link for each file opened.
Step S204:The link of the tab file of designated file name in the listed files that reading program process has been opened,
The tab file of corresponding designated file name is found by the link of reading.
The link of arrow mark file can be found from fd catalogues, i.e., if program has used aforementioned dynamically labeled description
Middle enumerated label, can find the link of direction/tmp/nonuseddirformark/abc_somevalue.
Based on same inventive concept, the embodiment of the present invention also provides a kind of marking program process using process filesystem
Device, the device can be arranged in host equipment, and structure is as shown in figure 3, include:Static tay module 301 and dynamically labeled
Module 302.
Static tay module 301, for for the program for needing static tay, before program startup, in environmental variance
Write-in token variable reads the ring before being brought into operation by the program of static tay in current process environmental variance list
Border variable reads program process mark from the token variable field of the environmental variance, restarts labeled program process;
Dynamically labeled module 302, for for dynamically labeled program is needed, being loaded into pre-set program in a program
Marker code opens the tab file of designated file name in agreement catalogue, search program by the programming indicia code of loading
The link of the tab file in the listed files that process has been opened.
Optionally, static tay module 301, is specifically used for:
Before program startup, the token variable of key assignments form is written by shell scripts, or token variable is write on into week
In the project crontab files that phase property executes, or token variable is write into corresponding system finger daemon systemd and is matched
It sets in file.
Optionally, dynamically labeled module 302, is specifically used for:
Programming indicia code is provided previously, described program marker code provides dynamically labeled application programming interface
At least one of API, including create label, delete label;
It is loaded into the described program marker code being provided previously in a program.
Optionally, dynamically labeled module 302, is additionally operable to:According to the fileinfo opened, the file opened is carried out
File addressing offset operation finds the offset address of tab file.
Optionally, above-mentioned apparatus further includes:
Identifier acquisition module 303, for when requiring to look up the label of program process, traversal is all to meet setting condition
Program process reads environment variable files, searches the program process mark being previously written;Traverse all journeys for meeting setting condition
Sequence process, the link of the tab file of the designated file name in the listed files that reading program process has been opened, passes through reading
Link find the tab file of corresponding designated file name.
The embodiment of the present invention also provides a kind of computer storage media, and being stored with computer in the computer storage media can
It executes instruction, computer executable instructions are for the above-mentioned method for marking program process using process filesystem.
The above-mentioned method for marking program process using process filesystem may be implemented to mark using procfs on linux
Remember that program process, such as PHP processes, correlated identities can be preserved after fork, can't lose;Correlated identities do not influence
Regular traffic;It is easy to use, it can be used for the program of various language, multilingual can also be used to handle correlated identities, may be used also
Just hold specific mark when so that program is started in crontab to be easily added to.
Bifurcated function in fork function computer programmings returns to two values, subprocess if successfully calling once
0 is returned to, parent process returns to subprocess label;Otherwise, error returns to -1.Fork functions by running program be divided into 2 it is (several
) duplicate process, each process starts a thread executed since the same position of code.The two processes
In thread continue to execute, be like two users while starting two copies of the application program.
Those skilled in the art will also be appreciated that the various illustrative components, blocks that the embodiment of the present invention is listed
(illustrative logical block), unit and step can pass through the knot of electronic hardware, computer software, or both
Conjunction is realized.To clearly show that the replaceability (interchangeability) of hardware and software, above-mentioned various explanations
Property component (illustrative components), unit and step universally describe their function.Such work(
Can be that the design requirement for depending on specific application and whole system is realized by hardware or software.Those skilled in the art
Can be for each specific function of applying, the realization of various methods can be used described, but this realization is understood not to
Range beyond protection of the embodiment of the present invention.
Various illustrative logical blocks or unit described in the embodiment of the present invention can by general processor,
Digital signal processor, application-specific integrated circuit (ASIC), field programmable gate array or other programmable logic devices, discrete gate
Or described function is realized or is operated in transistor logic, the design of discrete hardware components or any of the above described combination.General place
It can be microprocessor to manage device, and optionally, which may be any traditional processor, controller, microcontroller
Device or state machine.Processor can also be realized by the combination of computing device, such as digital signal processor and microprocessor,
Multi-microprocessor, one or more microprocessors combine a digital signal processor core or any other like configuration
To realize.
The step of method described in the embodiment of the present invention or algorithm can be directly embedded into hardware, processor execute it is soft
The combination of part module or the two.Software module can be stored in RAM memory, flash memory, ROM memory, EPROM storages
Other any form of storaging mediums in device, eeprom memory, register, hard disk, moveable magnetic disc, CD-ROM or this field
In.Illustratively, storaging medium can be connect with processor, so that processor can read information from storaging medium, and
It can be to storaging medium stored and written information.Optionally, storaging medium can also be integrated into processor.Processor and storaging medium can
To be set in ASIC, ASIC can be set in user terminal.Optionally, processor and storaging medium can also be set to use
In different components in the terminal of family.
In one or more illustrative designs, above-mentioned function described in the embodiment of the present invention can be in hardware, soft
Part, firmware or the arbitrary of this three combine to realize.If realized in software, these functions can store and computer-readable
On medium, or with one or more instruction or code form be transmitted on the medium of computer-readable.Computer readable medium includes electricity
Brain storaging medium and convenient for allow computer program to be transferred to from a place telecommunication media in other places.Storaging medium can be with
It is that any general or special computer can be with the useable medium of access.For example, such computer readable media may include but
It is not limited to RAM, ROM, EEPROM, CD-ROM or other optical disc storage, disk storage or other magnetic storage devices or other
What can be used for carry or store with instruct or data structure and it is other can be by general or special computer or general or specially treated
The medium of the program code of device reading form.In addition, any connection can be properly termed computer readable medium, example
Such as, if software is to pass through a coaxial cable, fiber optic cables, double from a web-site, server or other remote resources
Twisted wire, Digital Subscriber Line (DSL) are defined with being also contained in for the wireless way for transmitting such as example infrared, wireless and microwave
In computer readable medium.The disk (disk) and disk (disc) includes compress disk, radium-shine disk, CD, DVD, floppy disk
And Blu-ray Disc, disk is usually with magnetic duplication data, and disk usually carries out optical reproduction data with laser.Combinations of the above
It can also be included in computer readable medium.
Above-described specific implementation mode has carried out further the purpose of the present invention, technical solution and advantageous effect
It is described in detail, it should be understood that the foregoing is merely the specific implementation mode of the present invention, is not intended to limit the present invention
Protection domain, all within the spirits and principles of the present invention, any modification, equivalent substitution, improvement and etc. done should all include
Within protection scope of the present invention.