Linux??????
???????????? ???????[ 2014/5/26 13:18:25 ] ????????Linux ?????? ??????
??????????????????????????????????????????????????
????1????????????????????????????????????????????????????????????????????????????????????????????ж????????????????????????????????????????????????????????????????£????д???????????????????????????????????????????????????ж????????????????????????
????????????????
????int pipe(int pipe[2]); //????pipe[0]????????????????pipe[1]??д???????????
???????????????????????????????????й?????????????????????????????????????????????????????????????????
????2??????????????FIFO(FIRST IN FIRST OUT)????????????е????????(????????????????????????????/tmp/xxxx??)???????????????????????????????????????????????
????Unix/Linux ?????????????????????????????????(FIFO????????)??FIFO??????????????????ж?д??????ù????
?????????????????????mkfifo()
????FIFO????????????open()??close()??read()??write()??unlink()??????????????????
???????1.FIFO??????????????豸????????
????2.????????????????????????????
????3.??????FIFO?????????檔
???????1???????
include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
void read_data( int pipes[ ] ){
int c;
int rc;
close( pipes[ 1 ] ); //????????????????????д???????(???????)
while( (rc = read(pipes[ 0 ]?? &c?? 1)) > 0 ){ //????????????????????
putchar( c ); //int ?? unsiged char ????????
}
exit( 0 );
}
void write_data( int pipes[ ] ){
int c;
int rc;
close( pipes[ 0 ] ); //??????????
while( (c=getchar()) > 0 ){
rc = write( pipes[ 1 ]?? &c?? 1 ); //д????
if( rc == -1 )...{
perror ("Parent: write");
close( pipes[ 1 ] );
exit( 1 );
}
}
close( pipes[ 1 ] );
exit( 0 );
}
int main( int argc?? char *argv[ ] ){
int pipes[ 2 ];
pid_t pid;
int rc;
rc = pipe( pipes ); //???????
if( rc == -1 ){
perror( "pipes" );
exit( 1 );
}
pid = fork( );
switch( pid ){
case -1:
perror( "fork" );
exit( 1 );
case 0:
read_data( pipes ); //?????pipes
default:
write_data( pipes ); //?????pipes
}
return 0;
}
|
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11