做了一个有名管道的尝试,写在下面。
f1.c
#include
#include
#include
#include
#include
#include
#include
#define FNAME "kaka"
void main(int argc, char **argv[])
{
int fd;
char buf[256]="i am cai\n";
int len;
int ret = mkfifo(FNAME, S_IRUSR|S_IWUSR);
printf("111\n");
if(ret <0) exit(0);
fd = open(FNAME, O_WRONLY);
printf("222\n");
write(fd, buf, 256);
printf("now send:%s\n", buf);
sleep(1);
unlink(FNAME);
close(fd);
}
f2.c
#include
#include
#include
#include
#include
#include
#include
#define FNAME "kaka"
void main(int argc, char **argv[])
{
int fd;
char buf[256]="NULL\n";
int len;
fd = open(FNAME, O_RDONLY);
printf("111\n");
read(fd, buf, 256);
printf("now read:%s\n", buf);
close(fd);
}
makefile:
all : clean f1 f2
.PHONY : all
clean :
-rm *.o f1 f2 core
f1 : f1.o
cc -o f1 f1.o
f2 : f2.o
cc -o f2 f2.o
阅读(1402) | 评论(0) | 转发(0) |