Lecture
All that the Linux operating system consists of is files. Directories (folders, directories) are also files, only of a different type. In this lecture we will learn more about the so-called device files . Device files display the system hardware components in the system and allow them to interact with them.
Device files are divided into two types: block and character . You can also find in the literature block-oriented and byte-oriented . Differences between types in the way of “communication” with components. With block device files, information is exchanged in chunks or blocks. A typical block device is a hard disk. It should also be noted that information can be obtained from any part of the block device file . With symbolic device files, information is exchanged sequentially. An example of such a device is a com- port.
Run com *** at ls / dev / and look at the result. You will see the device files inherent in your hardware configuration. Consider first character -based device files . I have already mentioned devices such as tty (console) and ttyS0 (port com1 ). audio , dsp , mixer - file devices displaying a sound card. Virtual devices random and urandom - allow you to generate pseudo-random numbers. Moreover, the urandom device generates a sequence of purely mathematical methods, and random uses to generate the so-called “noise”, which is generated in the process of working with various hardware components. Log in to the second and third console. Type in the second console com *** at hexdump / dev / random . You should see hex numbers. Wait for a while and see how the number of numbers grows. To speed up the process you can go to the third console and press the keys. Return to the second console and interrupt the hexdump command by pressing ctrl + C. Now type the *** at hexdump / dev / urandom and see how the sequence of numbers is generated very quickly, since only mathematical methods of generating the sequence are used.
Two more interesting device files are zero and null . zero - always returns zeros. This may be necessary for example, if you need to clean the hard drive. To do this, you can use the com *** dd if = / dev / zero of = / dev / sdc . Just do not need to run this com *** u on your work disk. What does this com *** do? As input data ( if - input file ), information from / dev / zero (that is, zeros) is used, and a hard disk is used as data receiver ( of - output file ). As a result, the entire disk is filled with zeros. Null - does not contain anything. And writing to this device is writing to nowhere. This can be useful if we want to, the information issued by the *** *** s not displayed on the console. For example, com *** a echo Hello! > / dev / null will not display the word Hello !, on the console, since the output is redirected to / dev / null .
Let's run the *** command on the mount with no parameters to see which devices we have mounted and with which file systems. We are interested in the string related to the / proc directory. It looks like this: proc on / proc type proc (rw) . As you can see the file system here is called proc . This is a virtual file system in which file-processes are displayed. Linux creates this virtual file system in virtual memory, so it does not take up space on the hard disk, and many of the files in memory also do not take up space because they actually do not contain information. Run dom *** from df -ha and make sure that the / proc directory really takes up 0 bytes of space. Although the information can be obtained by the command cat (less) , but in fact this information is generated by the kernel on the fly - cat / proc / cpuinfo . That is, / proc / cpuinfo is not a text file. In other words, through the files contained in the / proc directory we get access to various statistical (and not only) kernel data. For example, com *** and cat / proc / net / dev will show statistical information on network devices - the number of received / transmitted bytes and packets and another. And the com *** and cat / proc / sys / net / ipv4 / ip_forward will show whether forwarding (forwarding) packets are allowed in our system. Most of the files in the / proc directory are read-only, but there are some that are writable (for the root user ). File ip_forward just refers to the latter. If you have 0 there, then forvarding is disabled. But we can enable it in the following way (in some distributions such operations will not work): e cho 1> / proc / sys / net / ipv4 / ip_forward . By this command, we will change the content from 0 to 1 and thereby allow forwarding (after rebooting the system will be 0 again). With the command ls / proc / you can see a lot of directories with a numeric name. These names correspond to the process identifiers running on the system. Each such folder contains a variety of information about the process. More details can be found by typing man 5 proc .
The / sys directory has its sysfs file system. In some ways, the contents of the directory (as intended) / sys are similar to the / proc directory. The main difference is that the files in / sys describe the actual configuration of the computer at the moment. / sys is very closely related to udev if you connect (disconnect) devices, the contents of the / sys directory change dynamically. You can look at an example. Run the com *** at ls / sys / bus / usb / devices / to view current usb devices in the system. Now connect the flash drive and run the com *** at ls / sys / bus / usb / devices / again. You will see that now there are more devices.
Once again I want to draw attention to the fact that the contents of the / proc and / sys directories are generated by the kernel during the boot phase. Boot from any LiveCD disk, go to the / proc and / sys directories on your disk and make sure they are empty.
In the next lecture we will talk about regular files and links.
Comments
To leave a comment
LINUX operating system
Terms: LINUX operating system