猪吃什么食物| plt是什么意思| 胃难受吃什么食物好| 蓝玫瑰的花语是什么| 脱肛是什么样子的| 什么叫易经| 黄体功能不足是什么原因造成的| 早上八点多是什么时辰| 扁桃体发炎吃什么食物| 糖类抗原125偏高是什么原因| 纤维硬结灶是什么意思| 子宫粘连有什么症状| 肛门里面痒是什么情况| oz是什么单位| 新生儿黄疸高有什么危害| 两边白头发多是什么原因造成的| 小孩子流鼻血是什么原因引起的| 为什么会得肺结核| 蓝色与什么色搭配好看| 存在感是什么意思| 墨镜偏光是什么意思| 2001年什么年| 缠腰龙是什么病| 利血平是什么药| 氪金是什么意思| 笔仙是什么| 狗冲什么生肖| 破伤风是什么意思| 耳结是什么原因造成的| 腿上长水泡是什么原因| 夏天喝什么茶比较好| upi是什么意思| 身体动不动就出汗是什么原因| 喜欢放屁是什么原因| 寻麻疹是什么症状| 验孕棒什么时候测准确| 磨牙是什么原因怎么治疗| 珍珠龟吃什么| 癫痫患者不能吃什么| psv医学是什么意思| 牙龈肿痛吃什么中成药| 1936年中国发生了什么| 胡麻是什么| 哥文花园女装什么档次| cook什么意思| 吃维生素b12有什么好处和副作用| fresh是什么意思| 吃什么能化解肾结石| 鱼加思读什么| 什么是概念车| 什么属相不能挂山水画| 为什么感觉不到饿| 拉杆箱什么材质好| 为什么种牙那么贵| 广西有什么市| 发生火灾时的正确做法是什么| 贫血去医院挂什么科| 吃素对身体有什么好处| 抗缪勒氏管激素是检查什么的| 遮羞布是什么意思| 血糖高适合喝什么茶| yq是什么意思| 流鼻血看病挂什么科| 舌苔黄腻吃什么药| 梦见栽树是什么预兆| 百合花什么时候种植| 吃什么降火| 章鱼属于什么类动物| 葡萄糖粉适合什么人喝| 鱼腥草泡水喝有什么功效| 脾大吃什么药能缩小| 胆汁酸高吃什么药| 省亲是什么意思| cooc香水是什么牌子的| 肚脐眼叫什么穴位| 星星像什么| 咖啡有什么好处和坏处| 河南南阳产什么玉| 盛夏是什么时候| 小腹痛挂什么科| 农历八月初三是什么星座| 甚好是什么意思| 什么玉便宜又养人| 生日派对是什么意思| 梦到龙预示着什么| 四个火字念什么| 花菜炒什么好吃| 初中老师需要什么学历| 突如其来什么意思| 2024年是什么年| 西康省是现在什么地方| 牛奶为什么能解辣| 尿黄是什么原因| 为什么鸡蛋不能和牛奶一起吃| 先兆临产是什么意思| 提拉米苏是什么| 胆结石挂号挂什么科| 姜黄粉是什么做的| 县公安局局长是什么级别| 男龙和什么生肖最配| 成吉思汗什么意思| 冰袋里面装的是什么| 霉菌反复发作是什么原因| 粉色象征着什么| 什么鬼大家都喜欢| 白马王子是什么意思| 827是什么意思| 甲状腺过氧化物酶抗体高说明什么问题| hisense什么牌子| 腋下有疙瘩是什么原因| 戍是什么意思| 河北有什么山| 婴儿什么时候会说话| 发改局是做什么的| exp是什么| 手背上有痣代表什么| 核医学科主要治什么病| 什么算高危性行为| 男士圆脸适合什么发型| fdg代谢增高是什么意思| 一拃是什么意思| 为什么会突然吐血| 血压低什么原因造成的| 熬夜吃什么维生素| 灰喜鹊吃什么| 指甲上的月牙代表什么| 尿蛋白微量是什么意思| 什么是香油| 满江红是什么植物| 小孩子腿疼是什么原因| 监护是什么意思| 卖萌什么意思| 男人更年期在什么年龄| 狮子座的幸运色是什么| 螳螂捕蝉黄雀在后是什么意思| jdv是什么牌子| 扁桃体发炎不能吃什么| 驴友是什么意思| uv是什么材质| dl是什么| 颈椎骨质增生吃什么药效果好| 六月二十一是什么日子| 胎盘宫底后壁是什么意思| 军长相当于地方什么官| 实性结节什么意思| 黑加仑是什么| 市政协秘书长是什么级别| 心肌缺血吃什么补得快| 女性什么时间是排卵期| 12min是什么意思| 下巴老是长痘痘是什么原因| 爆表是什么意思| 佛珠什么材质的最好| 1月25号什么星座| 何以是什么意思| 减肥吃什么玉米| 温暖的近义词是什么| 睡觉流口水吃什么药| 外阴萎缩是什么症状| 普洱茶有什么功效| 谋划是什么意思| 属鸡是什么命| 湿毒吃什么药最有效| 毛周角化症用什么药膏| 做头发是什么意思| 小孩拉肚子吃什么食物好| ferragamo是什么牌子| 针眼用什么眼药水| 落马是什么意思| 甲鱼和乌龟有什么区别| 英雄是什么生肖| 谛听是什么| 脸上长痘痘是什么原因引起的| 被老鼠咬了有什么预兆| cno什么意思| 鹅是什么动物| 高血脂是什么原因引起的| 难以启齿什么意思| 橡皮擦是什么材料做的| 传说中的狮身人面像叫什么名字| 肾上腺是什么意思| 收留是什么意思| 什么屎不臭| 膝盖不舒服挂什么科| 菠萝蜜吃了有什么好处| 幽门螺旋杆菌吃什么药| 剖腹产坐月子吃什么| 后期是什么意思啊| 虎皮膏药有什么功效| 扩心病是什么病| 白蛋白低吃什么补得快| 为什么手指会发麻| 自渡是什么意思| 吃什么对肠胃好| 震颤是什么病| 男人耳后有痣代表什么| 猪八戒的武器叫什么| 脆生生是什么意思| 嘴唇变厚是什么原因| 双减是什么意思| 什么东西泡脚减肥| 渗析是什么意思| 什么水果最甜| 即兴是什么意思| 喉咙老是有白痰是什么原因| 天蝎属于什么象星座| 9月14日是什么星座| 治疗湿疹吃什么药| syphilis是什么意思| 老铁是什么意思| 橘黄色是什么颜色| 硬度不够吃什么药| 经常拉肚子吃什么药好| 喜形于色是什么意思| 6月14日是什么星座| 4岁小孩流鼻血是什么原因| 荷花什么时候开| 石家庄以前叫什么名字| 周文王叫什么名字| 有口臭是什么原因引起的| 12月什么星座| 贫血会引起什么症状| 白芷泡水喝有什么功效| 这是什么| 面瘫吃什么药好得快| 2000年为什么叫千禧年| 梦见笑是什么意思| 迪奥什么意思| 子宫内膜异位症是什么意思| 贪污是什么意思| 风湿类风湿有什么区别| 小人得志是什么意思| 什么的知了| 冤家是什么意思| 腊月是什么星座| ov是什么意思| 塑胶厂是做什么的| 反应性增生是什么意思| 香肠炒什么菜好吃| 千里马比喻什么人| 强硬是什么意思| 渠道医院是什么意思| 地下党是什么意思| 梦见和别人结婚是什么意思| 抽筋是缺什么| 什么是化学| oppo是什么牌子| 胶水用什么能洗掉| 蛔虫属于什么动物| 肛门周围潮湿瘙痒是什么原因| 娅字五行属什么| 为什么要小心AB型血的人| 艺不压身是什么意思| 什么叫夏至| 4月3日什么星座| 什么颜色加什么颜色等于灰色| 左边小腹疼是什么原因| 腰椎退行性改变是什么意思| 独具一格是什么意思| 骨质疏松检查什么项目| 11月份是什么星座| 万能受血者是什么血型| 术后改变是什么意思| 内蒙有什么特产| 百度
The Open Group Base Specifications Issue 8
IEEE Std 1003.1-2024
Copyright ? 2001-2024 The IEEE and The Open Group

NAME

pipe, pipe2 — create an interprocess channel

SYNOPSIS

#include <unistd.h>

int pipe(int
fildes[2]);
int pipe2(int
fildes[2], int flag);

DESCRIPTION

The pipe() function shall create a pipe and place two file descriptors, one each into the arguments fildes[0] and fildes[1], that refer to the open file descriptions for the read and write ends of the pipe, respectively. The file descriptors shall be allocated as described in 2.6 File Descriptor Allocation. The FD_CLOEXEC and FD_CLOFORK flags shall be clear on both file descriptors. The O_NONBLOCK flag shall be clear on both open file descriptions. (The fcntl() function can be used to set this flag.)

Data can be written to the file descriptor fildes[1] and read from the file descriptor fildes[0]. A read on the file descriptor fildes[0] shall access data written to the file descriptor fildes[1] on a first-in-first-out basis. It is unspecified whether fildes[0] is also open for writing and whether fildes[1] is also open for reading.

A process has the pipe open for reading (correspondingly writing) if it has a file descriptor open that refers to the read end, fildes[0] (write end, fildes[1]).

The pipe's user ID shall be set to the effective user ID of the calling process.

The pipe's group ID shall be set to the effective group ID of the calling process.

Upon successful completion, pipe() shall mark for update the last data access, last data modification, and last file status change timestamps of the pipe.

The pipe2() function shall be equivalent to the pipe() function, except that the state of O_NONBLOCK on the new file descriptions and FD_CLOEXEC and FD_CLOFORK on the new file descriptors shall be determined solely by the flag argument, which can be constructed from a bitwise-inclusive OR of flags from the following list (provided by <fcntl.h>):

O_CLOEXEC
Atomically set the FD_CLOEXEC flag on both new file descriptors.
O_CLOFORK
Atomically set the FD_CLOFORK flag on both new file descriptors.
O_NONBLOCK
Set the O_NONBLOCK file status flag on both new file descriptions.

RETURN VALUE

Upon successful completion, 0 shall be returned; otherwise, -1 shall be returned and errno set to indicate the error, no file descriptors shall be allocated and the contents of fildes shall be left unmodified.

ERRORS

The pipe() and pipe2() functions shall fail if:

[EMFILE]
All, or all but one, of the file descriptors available to the process are currently open.
[ENFILE]
The number of simultaneously open files in the system would exceed a system-imposed limit.

The pipe2() function may fail if:

[EINVAL]
The value of the flag argument is invalid.

The following sections are informative.

EXAMPLES

Using a Pipe to Pass Data Between a Parent Process and a Child Process

The following example demonstrates the use of a pipe to transfer data between a parent process and a child process. Error handling is excluded, but otherwise this code demonstrates good practice when using pipes: after the fork() the two processes close the unused ends of the pipe before they commence transferring data.

#include <stdlib.h>
#include <unistd.h>
...

int fildes[2]; const int BSIZE = 100; char buf[BSIZE]; ssize_t nbytes; int status;
status = pipe(fildes); if (status == -1 ) { /* an error occurred */ ... }
switch (fork()) { case -1: /* Handle error */ break;
case 0: /* Child - reads from pipe */ close(fildes[1]); /* Write end is unused */ nbytes = read(fildes[0], buf, BSIZE); /* Get data from pipe */ /* At this point, a further read would see end-of-file ... */ close(fildes[0]); /* Finished with pipe */ exit(EXIT_SUCCESS);
default: /* Parent - writes to pipe */ close(fildes[0]); /* Read end is unused */ write(fildes[1], "Hello world\n", 12); /* Write data on pipe */ close(fildes[1]); /* Child will see EOF */ exit(EXIT_SUCCESS); }

APPLICATION USAGE

None.

RATIONALE

The wording carefully avoids using the verb "to open" in order to avoid any implication of use of open(); see also write().

The O_CLOEXEC and O_CLOFORK flags of pipe2() are necessary to avoid a data race in multi-threaded applications. Without O_CLOFORK, a file descriptor is leaked into a child process created by one thread in the window between another thread creating a file descriptor with pipe() and then using fcntl() to set the FD_CLOFORK flag. Without O_CLOEXEC, a file descriptor intentionally inherited by child processes is similarly leaked into an executed program if FD_CLOEXEC is not set atomically.

Since pipes are often used for communication between a parent and child process, O_CLOFORK has to be used with care in order for the pipe to be usable. If the parent will be writing and the child will be reading, O_CLOFORK should be used when creating the pipe, and then fcntl() should be used to clear FD_CLOFORK for the read side of the pipe. This prevents the write side from leaking into other children, ensuring the child will get end-of-file when the parent closes the write side (although the read side can still be leaked). If the parent will be reading and the child will be writing, there is no way to prevent the write side being leaked (short of preventing other threads from creating child processes) in order to ensure the parent gets end-of-file when the child closes the write side, and so the two processes should use an alternative method of indicating the end of communications.

Arranging for FD_CLOEXEC to be set appropriately is more straightforward. The parent should use O_CLOEXEC when creating the pipe and the child should clear FD_CLOEXEC on the side to be passed to the new program before calling an exec family function to execute it.

The O_NONBLOCK flag is for convenience in avoiding additional fcntl() calls.

FUTURE DIRECTIONS

None.

SEE ALSO

2.6 File Descriptor Allocation, fcntl(), read(), write()

XBD <fcntl.h>, <unistd.h>

CHANGE HISTORY

First released in Issue 1. Derived from Issue 1 of the SVID.

Issue 6

The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:

IEEE Std 1003.1-2001/Cor 2-2004, item XSH/TC2/D6/65 is applied, adding the example to the EXAMPLES section.

Issue 7

SD5-XSH-ERN-156 is applied, updating the DESCRIPTION to state the setting of the pipe's user ID and group ID.

Changes are made related to support for finegrained timestamps.

POSIX.1-2008, Technical Corrigendum 2, XSH/TC2-2008/0247 [835] and XSH/TC2-2008/0248 [467,835] are applied.

Issue 8

Austin Group Defects 411, 1318, and 1577 are applied, adding pipe2() and FD_CLOFORK.

Austin Group Defect 1576 is applied, adding the word "respectively".

End of informative text.

 

return to top of page

UNIX? is a registered Trademark of The Open Group.
POSIX? is a Trademark of The IEEE.
Copyright ? 2001-2024 The IEEE and The Open Group, All Rights Reserved
[ Main Index | XBD | XSH | XCU | XRAT ]

红鸾星动是什么意思 属羊的是什么星座 农历7月20日是什么星座 四肢麻木是什么原因引起的 什么情况需要做胃镜
陶和瓷有什么区别 化妆水是什么 热射病什么症状 什么驴技穷成语 势均力敌是什么意思
正月初八是什么星座 为什么小腹总是胀痛 行了是什么意思 象牙有什么作用与功效 三乙醇胺是什么东西
规培结束后是什么医生 事半功倍什么意思 听诊器能听出什么 右下腹痛挂什么科 女为悦己者容是什么意思
阴骘什么意思520myf.com 蓝莓是什么季节的水果hcv8jop0ns8r.cn 细菌性肠炎吃什么药hcv8jop5ns1r.cn 9.21是什么星座shenchushe.com 饭前饭后吃药有什么区别hcv9jop2ns6r.cn
脊膜瘤是什么样的病hcv8jop5ns3r.cn 辐照食品是什么意思wmyky.com 五行缺什么hcv9jop4ns2r.cn 梦见床上有蛇什么预兆jingluanji.com 牵牛花什么时候开hcv8jop0ns6r.cn
9.10是什么星座hcv8jop8ns9r.cn 物色是什么意思hcv8jop1ns3r.cn 蚕豆有什么营养hkuteam.com 东华帝君的真身是什么hcv9jop2ns0r.cn 淘米水洗脸有什么好处hcv9jop6ns9r.cn
老是什么意思hkuteam.com 潜血弱阳性什么意思hcv8jop2ns0r.cn 送礼物送什么好hcv8jop8ns2r.cn 腊月初六是什么星座hcv7jop9ns8r.cn 小腿肌肉痛什么原因hcv9jop0ns8r.cn
百度