????poll?????÷?????man????????????????????е??????
?????????????
????????????????????????
??????????????????????????????
????????????????????????shell????????500??????????????????"Testing...."
????????????????????
???????????????????????
????Ubuntu10.04:
????poll.cpp?????
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>// waitpid
#include <sys/types.h>// waitpid
#include <string.h>// strlen
#include <poll.h>// poll
/*
comment:
pipe is used between two processes on the same computer.
*/
#define TIMES 50
int main(){
int pipefds[2];
if( -1 == pipe( pipefds)){
printf( "Error when create pipes ");
}else{
int i;
pid_t pid = fork();
if( 0 == pid){// child
printf( "child running ");
close( pipefds[0]);
for( i = 0; i < TIMES; ++ i){
write( pipefds[1]?? "iamagoodguy"?? strlen( "iamagoodguy"));
sleep( 1);
}
}else{
printf( "parent running ");
char buf[256];
close( pipefds[1]);
struct pollfd pf[2];// key structure
pf[0].fd = 0;// console input
pf[0].events = POLLIN;// wait for bytes input
pf[1].fd = pipefds[0];// pipe input
pf[1].events = POLLIN;// wait for bytes input
for( i = 0; i < TIMES; ++ i){
poll( pf?? 2?? 500);// wait for only 500 ms
printf( "Testing... ");
if( pf[1].revents & POLLIN){
buf[ read( pipefds[0]?? buf?? 256)] = ' 主站蜘蛛池模板: 狠狠色狠狠色综合久久一 | 国产精品边做边接电话在线观看 | www.青草视频 | 国产精品欧美日韩 | 日本欧美一区二区三区在线 | 精品国产免费观看一区高清 | 成人欧美精品大91在线 | 天天综合天天做天天综合 | 欧美91精品久久久久网免费 | 成人国产精品久久久免费 | 午夜免费伦费影视在线观看 | 国产亚洲一区二区精品张柏芝 | 最新亚洲情黄在线网站 | 色综合久久综合网 | 欧美一级做一a做片性视频 欧美一级做性受 | 国内精品1区1区3区4区 | 日韩在线视频免费不卡一区 | 天天躁日日躁狠狠躁综合 | 午夜120秒| 翁熄系列乱吃奶小玲 | 五月天视频网 | 你懂的视频在线播放 | 综合激情区视频一区视频二区 | 中国一及黄色片 | 日本中文字幕在线精品 | 国产精品视频区 | 午夜高清影院 | 欧美三级一区二区三区 | 国产成年网站 | www.色五月.com | 高h喷水荡肉爽文np欲 | 欧美亚洲国产人成aaa | 欧美91精品久久久久网免费 | 一级女性全黄久久生活片免费 | www.91成人| 一区二区三区欧美 | 欧美妇性猛交视频 | 一级女性全黄生活片看看 | 国产性片在线 | 日本高清中文字幕一区二区三区 | 国产高清大尺度一区二区不卡 |