会员
周边
新闻
博问
闪存
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
謹
博客园
首页
新随笔
联系
订阅
管理
2026年9月19日
POSIX信号量实现线程同步(有名信号量):设计两个进程,进程A将自己的进程id写入到共享内存内,进程B在进程A完成任务后再id号串打印到终端
摘要: /*************** 进程A ****************/ #include <stdio.h> #include <sys/ipc.h> #include <sys/shm.h> #include <errno.h> #include <string.h> #include <u
阅读全文
posted @ 2026-09-19 00:28 謹
阅读(2)
评论(0)
推荐(0)
2026年9月18日
POSIX信号量实现线程同步(匿名信号量):设计一个含有两个线程的程序,主线程通过键盘输入字符串,子线程在主线程完成任务后再字符串打印到终端
摘要: #include <stdio.h> #include <semaphore.h> #include <strings.h> #include <string.h> #include <errno.h> #include <pthread.h> char buf[30]; sem_t sem; //
阅读全文
posted @ 2026-09-18 23:37 謹
阅读(4)
评论(0)
推荐(0)
互斥锁:在主线程里面生成子线程,实现两个线程互斥访问临界资源
摘要: #include <stdio.h> #include <pthread.h> #include <errno.h> #include <string.h> #include <unistd.h> int x; // 临界资源 pthread_mutex_t mutex = PTHREAD_MUTE
阅读全文
posted @ 2026-09-18 00:00 謹
阅读(5)
评论(0)
推荐(0)
2026年9月17日
pthread_join函数:利用子线程等待回收主线程的资源
摘要: #include <stdio.h> #include <pthread.h> #include <unistd.h> pthread_t pid; //存储主线程id void *con_do(void *arg){ int *main_statu; // 1.等待主线程结束并回收资源 pthre
阅读全文
posted @ 2026-09-17 17:59 謹
阅读(2)
评论(0)
推荐(0)
2026年9月16日
信号量:进程A创建共享内存和只有一个信号量的信号量组,且信号量的值为1,进程B和进程C通过信号量实现对共享内存的互斥访问
摘要: /**************** 进程A ****************/ #include <sys/ipc.h> #include <sys/shm.h> #include <sys/sem.h> #include <stdio.h> #include <errno.h> #include
阅读全文
posted @ 2026-09-16 17:36 謹
阅读(5)
评论(0)
推荐(0)
2026年9月15日
共享内存:进程A和进程B对共享内存里面的数据进行修改,进程C不断输出共享内存里面的数据,并观察效果(利用信号)
摘要: /************** 进程A *************/ #include <stdio.h> #include <sys/ipc.h> #include <sys/shm.h> #include <error.h> #include <errno.h> #include <signal
阅读全文
posted @ 2026-09-15 19:03 謹
阅读(6)
评论(0)
推荐(0)
2026年9月14日
消息队列:进程A给进程B发送SIGUSR1信号,进程B收到信号后往消息队列写入自己的进程id并给进程A发送SIGUSR2信号,进程A收到信号后读取数据并打印
摘要: /************** 进程A *************/ #include <sys/ipc.h> #include <sys/msg.h> #include <stdlib.h> #include <stdio.h> #include <signal.h> key_t key; int
阅读全文
posted @ 2026-09-14 23:56 謹
阅读(7)
评论(0)
推荐(0)
2026年9月12日
信号通信:在进程A中自定义信号SIGUSR1的响应接口,进程B向A传递SIGUSR信号,观察A是否响应信号
摘要: /*************** 进程A **************/ #include <signal.h> #include <stdio.h> int count = 0; // 自定义函数,接收到SIGUSR1信号后打印count数据 void printf_string(int sig)
阅读全文
posted @ 2026-09-12 21:48 謹
阅读(5)
评论(0)
推荐(0)
管道通信:进程A往管道写入时间日期数据,进程B从管道读入后写入到log.txt文本文件里面
摘要: /*************** 进程A *************/ #include <stdio.h> #include <fcntl.h> #include <unistd.h> #include <time.h> #include <sys/types.h> #include <sys/s
阅读全文
posted @ 2026-09-12 00:47 謹
阅读(6)
评论(0)
推荐(0)
2026年8月25日
利用GB2312汉字库往LCD屏幕中间写入汉字”啊“
摘要: /* * * 文件名:display_chinese.c * 功能:在 LCD 屏幕(1280x800)上显示一个 16x16 点阵汉字 * 说明: * - 使用 mmap 映射 /dev/fb0 显存,实现直接像素操作 * - 字库文件:HZK2312.Dzk(GB2312 16x16 点阵汉字库
阅读全文
posted @ 2026-08-25 20:08 謹
阅读(13)
评论(0)
推荐(0)
下一页
公告