码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 有名管道-


    1. //read.c
    2. #include<sys/types.h>
    3. #include<sys/stat.h>
    4. #include<stdio.h>
    5. #include<stdlib.h>
    6. #include<unistd.h>
    7. #include<fcntl.h>
    8. int main() {
    9. int fd = open("test", O_RDONLY);
    10. if(fd == -1) {
    11. perror("open");
    12. exit(0);
    13. }
    14. while(1) {
    15. char buf[1024] = {0};
    16. int len = read(fd, buf, sizeof(buf));
    17. if(len == 0) {
    18. perror("写端断开链接\n");
    19. break;
    20. }
    21. printf("recv buf: %s\n",buf);
    22. }
    23. close(fd);
    24. }
    1. //write.c
    2. #include<sys/types.h>
    3. #include<sys/stat.h>
    4. #include<stdio.h>
    5. #include<stdlib.h>
    6. #include<unistd.h>
    7. #include<fcntl.h>
    8. #include<string.h>
    9. int main() {
    10. int ret = access("test", F_OK);
    11. if(ret == -1) {
    12. perror("access");
    13. ret = mkfifo("test", 0664);
    14. if(ret == -1) {
    15. perror("mkfifo");
    16. exit(0);
    17. }
    18. }
    19. int fd = open("test", O_WRONLY);
    20. if(fd == -1) {
    21. perror("open");
    22. exit(0);
    23. }
    24. for(int i = 0; i < 100; i++) {
    25. char buf[1024];
    26. sprintf(buf,"hello, %d\n",i);
    27. printf("write data : %s", buf);
    28. write(fd,buf,strlen(buf));
    29. sleep(1);
    30. }
    31. close(fd);
    32. }

  • 相关阅读:
    Springboot毕业设计毕设作品,个人博客系统 开题报告
    SpringBoot之健康监控(Actuator)
    【CGAL_网格处理】平滑处理
    MST2102Q3 25A摩托车调压器控制芯片
    探花交友_第4章_MongoDB基础(新版)
    强大的协作工具 J2L3x,创造出高效敏捷的工作氛围
    人脸识别三部曲
    【Linux/脚本/芯片学习】Perl学习
    R语言清洗与处理数据常用代码段
    bert ranking listwise demo
  • 原文地址:https://blog.csdn.net/weixin_44273624/article/details/132921634
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号