Home
Home Page
Circuits of blocking in Databases
Blocking of the Table
Blocking of page
Compression of the data with a view of economy of a place and acceleration of job Oracle
Compression of the data with a view of economy of a place and acceleration of job Oracle
Service of events in the SQL-server
Offered variant of the decision
SQL Server in questions and answers
Boards - how to benefit
Development Ajax: Use XML in searches and answers
Transfer of pairs name / value (name/value)
Transfer XML on the server
All in the frameworks
Creation of wap-pages (in a format *.wml)
How to recover Perl/CGI a script
Mezhprocessovye interactions
Kill of the target data
Correctness at construction of a resource!
Example of a tree
Links
 

 

Mezhprocessovye interactions

At once I want to afflict programmers under Windows. Unfortunately, some from the recipes described below under Windows will not work. I and itself for a long time gnashed a teeth when in reply to redefinition STDOUT with the help branching out open in broad gullies messages that supposedly there is no such command fell. Whom here to blame, I do not know and to search I do not gather. And I advise everything to not spend precious time, to write the programs counting upon UNIX. To tell the truth, after all that I have gone through, programming under Windows, and having learned{having found out}, what the hosting on IIS is much more dear{expensive} (whether as very rare animal that?) than on UNIX-ah, I hardly from an armchair have not fallen out.

Processes and with what them eat


Very long time ago in one far galaxy once upon a time there was DOS. Also was at him{it} only navsego 640 kilov memories, and he could carry out only one problem{task}. Terrible monster Windows who has divided{shared} processor time for parts also has appeared. One part he sonmihhu procesov has allocated{removed}, and other part - sonmihhu streams. And pereklikalis` they with the help m`juteksov and semaphores. And the data were passed where as: Was there and a general heap (heap), and pajpy koj where worked: in general to tell I think further is not meaningful Still more many that is possible to write - all this boringly and distracts from the basic purposes.


As all here described is connected with Perl which was projected with orientation to UNIX-systems (I about it did not read, it is my own conclusion - if not rights, can correct), all system chesspieces which here will be rasmotreny, concern to UNIX-systems. Certainly, realization Perl for Windows hides some discrepancies, but is far from being all. So, strongly be not afflicted, if something does not work. Desperate situations it does not happen. Write to a forum, and experiment even better more - then all will turn out.


So, process is a program which code is carried out irrespective of other programs. There can be it and not the academic definition, but in fact and our problem{task} to not call it correctly, and to understand - as it works also what to us there can be from it an advantage{a benefit}. To not go deep into system subtleties, we shall present a situation on examples known to us.


The program written on Perl, contains some procedures. By a call of procedure, the interpreter carries out sequence of the operations making procedure - a body of procedure. Here it is important to allocate that this consistently, depends on sequence of operators of other procedure a little. In procedure local variables can be determined. These variables as have no attitude{relation} to the variables used in other procedures, even if names at them identical. Thus, any part of a code which is outside of any procedures, operates job of the program as a whole - when it is necessary causes procedures, something there still creates, and so on.


And so, it is possible to result analogy to multitask operational system: the code outside of procedures will represent here a code of a nucleus which operates all processes - procedures. But here the small but important note. When in our analogy the nucleus causes procedure it is start of process, but not its{her} performance and expectation of its{her} end. The nucleus somewhere there at itself in khehshe procesov creates a new pair name - value which name is a name of procedure, and value - number{room} of a line of sequence of operators of procedure on which performance (that is after start it is 0) has stopped. After that, the nucleus touches all keys from khehsha looks at a name and number{room} of a line. Passes to this line in the necessary procedure and carries out, for example, the following five lines. Further the following procedure, so up to the end, and then again in the beginning khehsha.


Well, at us the primitive multitask environment has turned out. Even she{it} can be complicated with a summer. For example, to add concept of a priority procesa. In our example, the above the priority, the is more than lines of procedure will be carried out in each iteration perebora all processes - procedures.


Actually all is much more complex{difficult}. But it is not necessary for us to know as the nucleus of operational system would work for that what to use advantages of the multitask environment. It is enough to know, that process is the program, carried out independently. It is very important to understand, that process it not only a code, but also the data. Even if two identical programs are started, given they will process, most likely, on miscellaneous.


From the point of view of programming when speech does not go about start of other program, in Perl creation (generation) of new process is a creation of the duplicate of the current program. Thus once again podmechu, that is duplicated not only a code, but also all variables with their values. All is done{made} not simply, and is very simple


fork;


And after that operator at you completely identical two processes are carried out. Well, certainly from the program, the carrying out operator fork in such kind, is not enough sense, unless if you want to salt{do a bad turn} to the system administrator, devouring system resources, having started this operator in an infinite cycle.


Actually, the operator fork returns value which is used for definition of process. For example, the person because of a corner, and to him a brick on a head leaves. Has regained consciousness, and in a hand at him{it} on a piece of paper it is written - you number{room} 1. He has risen and has gone further. To go that has gone, yes on his{its} place besides this person lays. And at him{it} in a hand a piece of paper on which it is written - you number{room} 2. This person has risen, has thought, that now zajdu of other corner, and there again a brick on a head will give, and has gone to other party{side}.


And so, we shall return to our rams. procesu the value identifying generated process gets to one. That is, we finish in a piece of paper of the first person a phrase such as " at the second number{room} 2 ". It happens necessary in a case if interaction with the generated process is meant. The generated process, receives from fork value 0. But such erroneous situations are possible{probable} when to create process it was not possible. Coming back to our example, the person comes for a corner and: occurs nothing. The person thinks, strange, here the brick, probably weather should fall to me non-flying. It is developed{unwrapped} and goes home. When fork does not return value (undef), means to generate process it was not possible. It, undoubtedly, an erroneous situation and her{it} it is necessary to process. Generally the call fork should look so



unless defined (fork) {

        print " process a mistake, or instead of it call die "

}


Probably you already perekrjuchilo, in vain attempts otryvanija fingers from the liked keyboard. Let's try apply our knowledge about fork on what nibud` (as always useless) an example.



*!/usr/bin/perl-w

* fork.pldie " Non-flying weather "

unless defined (fork);

print " I'm number $$ n ";


As a result of performance you uvidete something like



[root@avalon tests] * ./fork.pl

I'm number 6773

I'm number 6774


As processes are completely duplicated, each process receives own copy of the data, including file descriptors and descriptors of streams of input-output. Thus, the operator print in both processes works with the same descriptor. If who does not know, the built - in variable $$ contains the identifier of current process Perl. By the way, as the domestic task, can add a code showing value of a variable $$ before performance fork. Then you uvidete, what process is parental and to draw a conclusion - in what sequence two duplicates start to work.


Yes, nearly has not forgotten, it is important to finish process by the operator exit. Well, I think, the useless literary trash will suffice from you. It is time to engage that nibud` in more serious.