mmap將一個文件或者其它對象映射進內存。文件被映射到多個頁上,如果文件的大小不是所有頁的大小之和,最後一個頁不被使用的空間將會清零。
http://kenby.iteye.com/blog/1164700
4、Pips
管道兩端可分別用描述字fd[0]以及fd[1]來描述,需要注意的是,管道的兩端是固定了任務的。即一端只能用於讀,由描述字fd[0]表示,稱其爲管道讀端;另一端則只能用於寫,由描述字fd[1]來表示,稱其爲管道寫端。如果試圖從管道寫端讀取數據,或者向管道讀端寫入數據都將導致錯誤發生。一般文件的I/O函數都可以用於管道,如close、read、write等等。
從管道中讀取數據:
- 如果管道的寫端不存在,則認爲已經讀到了數據的末尾,讀函數返回的讀出字節數爲0;
5、Socket
socket的英文原義是“孔”或“插座”。作爲BSD
UNIX的進程通信機制,取後一種意思。通常也稱作"套接字",用於描述IP地址和端口,是一個通信鏈的句柄。在Internet上的主機一般運行了多個服務軟件,同時提供幾種服務。每種服務都打開一個Socket,並綁定到一個端口上,不同的端口對應於不同的服務。Socket正如其英文原意那樣,像一個多孔插座。一臺主機猶如佈滿各種插座的房間,每個插座有一個編號,有的插座提供220伏交流電,
有的提供110伏交流電,有的則提供有線電視節目。 客戶軟件將插頭插到不同編號的插座,就可以得到不同的服務。
The domain parameter specifies a communication domain; this selects the protocol family which will be used for communication. These families are defined in <sys/socket.h>. The currently understood formats include:
Name | Purpose | Man page |
PF_UNIX,PF_LOCAL | Local communication | unix(7) |
PF_INET | IPv4 Internet protocols | ip(7) |
PF_INET6 | IPv6 Internet protocols | |
PF_IPX | IPX - Novell protocols | |
PF_NETLINK | Kernel user interface device | netlink(7) |
PF_X25 | ITU-T X.25 / ISO-8208 protocol | x25(7) |
PF_AX25 | Amateur radio AX.25 protocol | |
PF_ATMPVC | Access to raw ATM PVCs | |
PF_APPLETALK | Appletalk | ddp(7) |
PF_PACKET | Low level packet interface | packet(7) |
The socket has the indicated type, which specifies the communication semantics. Currently defined types are:
- SOCK_STREAM
- Provides sequenced, reliable, two-way, connection-based byte streams. An out-of-band data transmission mechanism may be supported.
- SOCK_DGRAM
- Supports datagrams (connectionless, unreliable messages of a fixed maximum length).
- SOCK_SEQPACKET
- Provides a sequenced, reliable, two-way connection-based data transmission path for datagrams of fixed maximum length; a consumer is required to read an entire packet with each read system call.
- SOCK_RAW
- Provides raw network protocol access.
- SOCK_RDM
- Provides a reliable datagram layer that does not guarantee ordering.
- SOCK_PACKET
- Obsolete and should not be used in new programs; see packet(7).
Some socket types may not be implemented by all protocol families; for example,SOCK_SEQPACKET is not implemented for AF_INET.