In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the knowledge about "what are the common special devices in linux dev". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!
Linux is a file-based system, and all hardware such as software will have corresponding file representations under the directory for. For dev, we know that the files below represent linux devices. In windows, devices are well understood, like hard disks, and disks refer to physical hardware. And under linux for file systems, there are files associated with these devices. Access them and you can put them on real hardware. Think linux is flexible. Into a file, how easy it would be. there is no need to call com,prt, etc. interfaces before. Read files directly, write files can send read or write operations to the device. According to the way of reading and writing data, we can divide the devices into the following types: character devices, block devices, and pseudo-devices.
I. Equipment classification
character device
Character devices are devices that transmit one character at a time with the system. These device nodes typically provide streaming services for devices such as fax, virtual terminals and serial modems, keyboards, etc., and typically do not support random access data. Character devices are mostly implemented without buffers. The system reads/writes each character directly from the device. For example, a keyboard is a device that provides a stream of data. When you type the string "cnblogs," the keyboard driver returns a stream of seven characters in exactly the same order as you typed them. They are sequential, returning c first and s last.
block device
Block devices are devices that move data between systems in blocks. These device nodes typically represent addressable devices such as hard disks, CD-ROMs, and memory areas.
Block devices typically support random access and addressing and use buffers. The operating system allocates buffers for input and output to store a block of data. When a program sends a request to read or write data to a device, the system stores each character in the data in the appropriate cache. When the cache is full, the appropriate action is taken (the data is transferred) and the system empties the cache. It differs from character devices in that it supports random access storage. Character type is stream form, stored one by one.
pseudo device
In Unix-like operating systems, device nodes do not necessarily correspond to physical devices. A device without such a correspondence is a pseudo-device. Operating systems utilize the many functions they provide. Some commonly used pseudo-devices include null,zero,full,loop,random, urrandom
II. Special equipment and use
When it comes to special devices, in addition to hard disk motherboards, etc., it only has a special role in the linux shell command, so take them out separately. These are:
/dev/stdin
/dev/stdout
/dev/stderr
/dev/null
/dev/zero
/dev/full
/dev/random,urandom
/dev/fd
/dev/tcp|upd
/dev/loop
1, standard output input equipment
Remember last time, linux redirection? See: linux shell data redirection (input redirection and output redirection) detailed analysis. They correspond to several special file descriptors, fd0,fd1,fd2 (stdin,stdout,stderr)
For example:
[chengmo@centos5 shell]$ cat>teststdinteststdintest#ctrl+D#No input specified, default input device is/dev/stdinn
/dev/stdin refers to keyboard devices
[chengmo@centos5 shell]$ cat test.sh >/dev/stdout |grep 'echo'echo "very good! ";echo "good! ";echo "pass! ";echo "no pass! "#/dev/stdout points to standard output, so redirect data to it and end up on the screen (fd1) [chengmo@centos5 shell]$ cat test.sh |grep 'echo' echo "very good! ";echo "good! ";echo "pass! ";echo "no pass! "; [chengmo@centos5 shell]$ cat test.sh >/dev/stderr |grep 'echo' #!/ bin/sh scores=40;if [[ $scores -gt 90 ]]; then echo "very good! ";elif [[ $scores -gt 80 ]]; then echo "good! ";elif [[ $scores -gt 60 ]]; then echo "pass! ";else echo "no pass! ";fi;#/dev/stderr refers to error output, which is output to the screen by default, but its contents cannot be passed to grep through pipes, pipes can only pass standard output
/dev/null Device
A null device is a black hole device that discards everything written to it. A null device is usually used to discard unwanted output streams. I remember when I used Windows, there was a similar device: NUL, which had the same function as this one. Any data written to the device is discarded. Reading data from this returns null. Send unwanted content to the device often and discard unwanted data.
For example:
[chengmo@centos5 shell]$ cat /dev/null[chengmo@centos5 shell]$ cat test.sh>/dev/null#Read this device is empty, write this device data are discarded
/dev/zero Devices
In UNIX-like operating systems, /dev/zero is a special file that provides infinite null characters (NULL, ASCII NUL, 0x00) when read. One typical use is to overwrite information with the stream of characters it provides, and another common use is to produce a blank file of a specific size.
For example:
[chengmo@centos5 shell]$ dd if=/dev/zero of=testzero count=1024 bs=10241024 + 0 records in 1024 + 0 records out1048576 bytes (1.0 MB) copied, 0.0107194 seconds, 97.8 MB/s#Create a file of 1M size, which is 1024 bytes in a block, totaling 1024 blocks (exactly 1M), and fill it with the contents of the/dev/zero file. Output created to: testzero file [chengmo@centos5 shell]$dd if=/dev/zero of=/dev/disk partition #This command must not be used casually, a bit like the shredding file tool in windows. But it fills the entire partition with\0x00. The data cannot be recovered. [chengmo@centos5 shell]$cat /dev/zero>testinputzero#This command also cannot be used casually,/dev/zero device A special effect is that if you read it, it is an endless loop that outputs infinite\x00, so you will create a file filled with\x00. If you do not limit disk quotas for this user. It will consume the entire disk space.
In linux resource quota limits, if there is no disk space utilization or memory usage for ordinary users now. An ordinary user can fill up the disk in a moment by using the above method. You can also use while(true) {fork...} class programs to start infinite threads and exhaust the entire system memory.
/dev/full devices
On Unix-like systems,/dev/full is a special device file that always returns no free space on the device when written to (error code ENOSPC) and returns infinite null characters (NULL, ASCII NUL, 0x00) when read, similar to/dev/zero. This device is often used to test the behavior of programs that encounter disk no free space errors.
For example:
[chengmo@centos5 shell]$ echo 'chengmo' >/dev/full-bash: echo: write error: No space on device [chengmo@centos5 shell]$ echo $? 1#command execution returns error
/dev/random[urandom]
In UNIX-like operating systems,/dev/random is a special device file that can be used as a random number generator or pseudo-random number generator. It allows programs to access background noise from device drivers or other sources. Often used as a random number generator. Specific reference: linux shell to achieve a variety of random number methods (date,random,uuid)
/dev/fd
Record file descriptors opened by user
[chengmo@centos5 shell]$ ls /dev/fd/
0 1 2 3
Detailed Reference:
Linux shell data redirection (input redirection and output redirection) detailed analysis file descriptor introduction.
/dev/tcp[udp]/host/port
Reading this form of device creates a tcp[upd] connection to the host port. Open a socket communication interface.
For more details, please refer to:
Linux shell script implementation tcp/upd protocol communication (redirect application)
/dev/loop
In UNIX-like operating systems, Loop devices can mount loop files as block devices.
For example:
[chengmo@centos5 shell]$mount -o loop example.img /home/chengmo/img
#Mount the img image file to/home/chengmo/img directory. With this device, we can read files in virtual disk format without using virtual drive.
Said a lot of linux special equipment, other things like cpu, memory, disk, network, keyboard, terminal equipment. It's pretty much what we see in Windows.
"What are the common special devices in linux dev" is introduced here. Thank you for reading it. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.