read
方法 - 同步非阻塞I/O模型
#include <unistd.h>
ssize_t read(int fd, void *buf, size_t count);
On files that support seeking, the read operation commences at the file offset, and the file offset is incremented by the number of bytes read. If the file offset is at or past the end of file, no bytes are read, and read() returns zero.
If count is zero, read() may detect the errors described below. In the absence of any errors, or if read() does not check for errors, a read() with a count of 0 returns zero and has no other effects.
read
轮询方法对应read()
系统调用。即用户线程需要在一定时间间隔内非阻塞地持续发起轮询请求来获知此I/O操作的当前状态。因此,轮询操作是由用户线程来负责的。
虽热用户线程不会被阻塞,但它需要不停地发起系统调用,直到数据可用为止。
它是较原始、性能较低的一种,不仅整体数据吞吐量较低,而且(相较于阻塞式系统调用)消耗了额外的CPU资源。
Reference
- https://man7.org/linux/man-pages/man2/read.2.html
- https://man7.org/linux/man-pages/man3/read.3p.html
FEATURED TAGS
algorithm
algorithmproblem
architecturalpattern
architecture
aws
c#
cachesystem
codis
compile
concurrentcontrol
database
dataformat
datastructure
debug
design
designpattern
distributedsystem
django
docker
domain
engineering
freebsd
git
golang
grafana
hackintosh
hadoop
hardware
hexo
http
hugo
ios
iot
java
javaee
javascript
kafka
kubernetes
linux
linuxcommand
linuxio
lock
macos
markdown
microservices
mysql
nas
network
networkprogramming
nginx
node.js
npm
oop
openwrt
operatingsystem
padavan
performance
programming
prometheus
protobuf
python
redis
router
security
shell
software testing
spring
sql
systemdesign
truenas
ubuntu
vmware
vpn
windows
wmware
wordpress
xml
zookeeper