- roll-service.by

Planning in the operating system UNIX

At the last lecture we saw how the plan can be implemented in the operating system UNIX. We determined that, in principle, the planning system are two types of processes. The first type - these are processes that are in RAM, and that happens between the time the division of the CPU. We found that this mechanism is quite simple and based on a calculation of the value of priority. And what happens if the system component reaches its maximum value? In this case, the process will simply lower priority. The second type of processes - processes that are on the disc - planning to swap. Any process in the system can be in two states - either he is otkachan on DDT, or he is located in RAM. And as in other cases with a value associated P_TIME, which grows as a process in this particular condition. This value obnulyaetsya, when the process of changing its status (that is pumped into RAM, or vice versa). In turn, the system uses P_TIME as the value of a priority (the higher the value, the more likely it is that the process of changing its status).
The question that is the reason for initiating action to dokachke process from the swap of RAM. This question has no single answer, because in every UNIX-e has been done on its own. There are two solutions. The first is that when you reach a certain boundary values P_TIME operating system begins to try his perekachat in RAM for further processing. A second possible solution could be that there are certain conditions on a system component of zero (zero process - this is the kernel). Once in a situation arises that the nucleus begins to work a lot - it is a sign that the system nedogruzhena, ie the system can be a lot of processes in memory, but they are all engaged in the exchange, and the CPU idle. The system can be in this situation, some processes are pumping, and some put in multiprogrammnuyu processing.
We talked about that a different UNIX-y may represent a different process during his treatment. Some UNIX-s represent the body process as a whole (and the code and data), and all movements are carried out according to what is a unified whole. Some (modern) UNIX-y process of considering how to combine the two segments - the segment of code and data segment. A related problem launching processes, planning time and planning processor swap.
When you start a process of the system must understand whether this process as already running, so as not to run extra code segment, and attach the new data to the already functioning code segment. This is defined quite simply - in the context of the process is setting, which includes the value ID (inode) file, which was launched this process. And when the system tries to load a new process (from file), then to those carried out by viewing the context of existing processes, and the system is watching, whether already in the memory process with the specified ID, that is Process, launched from the same file. Same happens with the record svopirovanii, ie first svopirovaniyu given segments of data, and then may be considered code segments. I draw attention to that, in carrying out the functions exec in the process of changing the relevant information about the ID.
I recall that the objective of our course is not a study of how to implement a function in a version of UNIX. We want to see how this can be done, that you have no sense of wonder when you see the operating system, and you do not wade tremor, which is something supernatural. Everything is simple. There is a rule: the more the system is a program, the more transparent should be Algorithms and used the idea. Tricky programs are difficult, and this is confirmed by practice. Transparent program live long. Example - UNIX - transparent program, and an example of Windows - a program built on a very high level, but there is no transparency at all levels, and, unfortunately, the system has enough features that lead to unpredictable results of its work. So everywhere. If we look programming languages - was absolutely fantastic draft language ADA, when the competition was formed by several professional teams, which develop language late XX century. He was to be able to do everything. Been very beautiful thing. From a professional point of view, this language in all good, but he found no practical application because it is complicated. It talentless Si language exists and will exist for a long time. The same can be said about the languages Virta (the uncle, who invented the Pascal, Modula and Oberon) - they do not prizhilis.

The processes and collaboration processes

Since that time, we are beginning a long and hard to consider various ways of interaction processes in the operating system UNIX. A small technical appendix. I now you prodeklariruyu two system functions which we will use later. This duplication of the functions of file descriptors (FD).
int dup (fd); int dup2 (fd, to_fd);
int fd; int fd, to_fd;
The argument dup function is an open file descriptor in the process file. This function returns -1 if the treatment has not, and the value greater or equal to zero, if the work function successfully completed. Work function is that carried out the duplication of FD in some free FD, that is You can duplicate to open the file.
The function dup2 duplicate the file descriptor fd in some file descriptor with the number to_fd. In doing so, if when you access this feature, FD, which we want to duplicate, was busy, then going on closing the file, working with the FD, and the redefinition of FD.
int fd;
char s [80];
fd = open ( a.txt, O_RDONLY);
dup2 (fd, 0);
close (fd);
gets (s, 80);

The program opens a file named a.txt read-only. FD, which will be linked with this file is fd. Next, the program appealed to function dup2, leaving will be replaced by standard input process to work with the file a.txt. Then you can close the descriptor fd. The function gets read another line from the file a.txt. You see, that redefinition is very simple.

The program channels. First a few words about the concept. There are two processes, and we want to organize interaction between these processes by transferring data from one process to another. In the UNIX system for this purpose are used so-called channels. In terms of the program, the channel has a certain essence, with two FILEHANDLE. After one FD can write information to the channel through another FD can read information from the canal. As the channel is something associated with a file descriptor, the channel can be transmitted by inheritance filial processes. This means that two relatives process may have the same channel. This means that if a process to record some information to the channel, the other can read this information from the same channel.
Features of the Canal. By storing information transmitted via the channel allocated a certain fixed amount of memory. In some systems, this buffer can be continued for external memory. What happens if a process wants to write information to the channel, a buffer is full, or read information from the canal, and in the buffer no data yet? In both cases, the process stops its execution and waits until you free up space or, respectively, while the channel does not appear information. Note that in these cases, the work process may vary depending on the settings that you can change the software (and the reaction to these situations may not be waiting, and return a response code).
Let's see how these concepts are implemented in the system. There is a function of pipe. The argument of this function should be a pointer to an array of entire two variables.
int pipe (pipes);
int pipes [2];
Zero element of the array after a function pipe gets FD for reading, the first element of the array receives FD for the record. If there is no free FD, this function returns -1. Symptom end of the file descriptor for the reader will not be received until not closed all the descriptors associated with entry into the channel. Consider a simple example:
char * s = This is an example;
char b [80];
int pipes [2];
pipe (pipes);
write (pipes [1], s, strlen (s) +1);
read (pipes [0], s, strlen (s) +1);
This is an example of copying the line (it is understandable that both do not have to copy lines, and generally, no one function pipe in one process does not use). In this example, and not processed in subsequent refusal. Now let's look more interesting example. Write a sample program that will start and will connect the two channel process:
main ()
int fd [2];
pipe (fd); / * in the process of forming two paternal channel descriptor * /
if (fork ()) / * forming process-son, who will be the same descriptors * /
(/ * This part of the program occurs in the father-* /
dup2 (fd [1], 1); / * replace the standard output finding a channel * /
close (fd [1]); / * close descriptors channel * /
close (fd [0]); / * So now the entire withdrawal will take place in the channel * /
execl ( / bin / ls, ls, (char *) 0) / * replace the body of his father at ls * /
) / * From here starts the process-son * /
dup2 (fd [0], 0); / * in the son all makes a similar * /
close (fd [0]);
close (fd [1]);
execl ( / bin / wc, wc, (char *) 0);
This example binds conveyor two teams - ls and wc. Ls command displays the contents of the directory, and command wc counts the number of rows. This gives our program will be counting rows retired command ls.
In the process of paternal start the process ls. All information ls output loads in the channel, because we have a standard output device associated with the channel. Then we start in the son wc, whose standard input device (ie, where wc reads the information) associated with the descriptor read from the canal. This means that all that will write ls in its standard output device, will arrive at a standard input command wc.
We talked about that, in order to channel worked correctly, and reads the descriptor was a sign of the end of the file should be closed, all writing descriptors. If the program would not be given dedicated line, the process of wc hovered like, because in this case the function Reading from a channel, not wait for the trait end of the file. It will expect him indefinitely. In the father stressed the row could be omitted, because descriptor would be closed at the conclusion of the process, and in the son of such a line is needed. Ie conclusion is: the final part of the descriptors should be closed all channels associated with the record.
Canal can bind only related processes. Technically, you can connect multiple processes one channel, but problems may arise.


Proxy Server - This effective way of protecting information as well as a barrier to attack, hackers
Linux: Gentoo Vs Ubuntu Functionality
The company Janet Systems Provedet Roundtable The future of Soa-Projects
Basics With Virtualdub
Playing audio and video files
Erg-exercises to improve posture
Automation planning printing by Apple (Mac)
Maintenance of computers in the Framework for IT outsourcing
Restoring Windows
The device Netping Cooler Board Received At Warehouse Company Zao Light Kommunikeyshn
Theft of computer data
Learn the truth about your child doing surfing habits
Linear Magnetic Recording Dlt (Dlt-V/Sdlt/Dlt-S4)
The development of databases on Msde 2000, working with Free Database Mssql
Windows Vista: When ends Diskspace
3Ds Max 2008 (Rip)
Microprocessors used in CompactPCI-systems
Concentrators Ethernet NetGear
Hold printing
Preventive methods that reduce fatigue while working for a computer
The company Janet Systems Llc Presented Soa-Platform The exhibition E-Kazakhstan
Loading the alternative mode
Marking + control autopsy with labels B-367
On Legalization. Price Errors!
The structure design and generation of computers
Soa-platform Ijanet Free
The physical medium for LANs
Potential problems in Windows
Introducing the expense of medical software - to allow for medical centers
Graycatsoft - Server Software
New Decision on the market Soa
The destruction of computer data
Tips and Tricks - Picasa will
Why is cleaning Windows registry needed
The truth of the activation of Windows Vista
Animation on your computer desk
Team-quality design of computer
Run Windows
Integration Ibm Rational Clearquest and Microsoft Project - The key to successful planning
Introduction to Windows
Local bus
Checking Software Licensing
Geographic Information Systems (GIS) as a means of collecting and analyzing Geodannyh
The reverse side of the coin Spyware
How Stress Editor In Word 2007
Why work for a computer is harmful to human health
Computer data as an object of criminal assault
Odbc Firebird or may be still Ole Db driver?
Ergonomic organization of the workplace
How to make the right choice? 1C: Enterprise 7.7. or 8.0