上海配资网站开发,列出寻找网站关键词的几种途径,怎样申请自己企业的网站,网站建设横幅系列素材我理解#xff0c;fifo 就是一文件。其实#xff0c;一般文件也可以在进程间传递信息#xff0c;只要控制好进程间的读写互斥就行了
进程一#xff1a;特别要注意mkfifo第二个参数#xff0c;它是生成文件的权限参数。用0666 就行。
#include stdio.h
#include …我理解fifo 就是一文件。其实一般文件也可以在进程间传递信息只要控制好进程间的读写互斥就行了
进程一特别要注意mkfifo第二个参数它是生成文件的权限参数。用0666 就行。
#include stdio.h
#include unistd.h
#include wait.h
#include string.h
#include stdlib.h
#include string.h
#include unistd.h
#include sys/select.h
#include arpa/inet.h
#include wait.h
#include sys/socket.h
#include sys/stat.h
#include fcntl.h
#include errno.h
#define PATH /home/wzpc/fifo1int main(void){mkfifo(PATH,0666);int fd open(PATH, O_WRONLY);write(fd,hello,5);close(fd);return 0;
}
进程二
#include stdio.h
#include unistd.h
#include wait.h
#include string.h
#include stdlib.h
#include string.h
#include unistd.h
#include sys/select.h
#include arpa/inet.h
#include wait.h
#include sys/socket.h
#include sys/stat.h
#include fcntl.h
#include errno.h
#define PATH /home/wzpc/fifo1int main(void){int dopen(PATH,O_RDONLY);if(d-1){puts(file error);}char c[5]{};read(d,c,5);printf(%s\n,c);return 0;
}
先起动进程一后程序一一直等待直到起动进程二后进程一才退出等待继续执行。这样就完成了两进程的互斥交换数据。
或者先启动进程二此进程也会等待直到启动进程一后进程二退出等待继续执行。
也就是说如进程的读写fifo不设成非阻塞状态先启动的一方必等待另一方启动后交换了数据才会退出阻塞等待。保证了读写FIFO的成功。