projects
/
Linux_API.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
f8e9e8d
)
delete some logs
master
author
yu.dongliang
<18588496441@163.com>
Tue, 6 Aug 2024 09:20:14 +0000
(17:20 +0800)
committer
yu.dongliang
<18588496441@163.com>
Tue, 6 Aug 2024 09:20:14 +0000
(17:20 +0800)
shm.c
patch
|
blob
|
blame
|
history
diff --git
a/shm.c
b/shm.c
index d6d576e025bfbc523ff31625a23b144cdac26bbf..3461e65663a534933e8a502b91185a2207f78503 100644
(file)
--- a/
shm.c
+++ b/
shm.c
@@
-98,17
+98,8
@@
typedef struct {
volatile int count;
} shm_t;
volatile int count;
} shm_t;
-// 共享内存里的数据,怎么布局
-
int main()
int main()
-{// shm: shared memory
-/* flags:
- O_RDWR 可读可写, O_RDONLY 只读, O_WRONLY 只写.
-
- O_CREAT 如果不存在就创建
-
- Linux 进程间通信的机制之一,共享内存, socketpair.
- */
+{
int fd = shm_open("shm_obj", O_RDWR | O_CREAT | O_TRUNC, 0666);
if (fd < 0) {
printf("shm_open error, errno: %d\n", errno);
int fd = shm_open("shm_obj", O_RDWR | O_CREAT | O_TRUNC, 0666);
if (fd < 0) {
printf("shm_open error, errno: %d\n", errno);
@@
-130,12
+121,6
@@
int main()
shm->count = 0;
int n = 0;
shm->count = 0;
int n = 0;
-//-----------------
-// 多进程 程序,需要在父子进程之间 "共享的数据",全在fork()之前申请
-
-// 程序员 对 内核 + 编译器 填坑!
-
-// 人脑的思维 至少 比电脑高一个维度!
pid_t cpid = fork(); // 把 父进程 复制 一份 到子进程
if (-1 == cpid) {
pid_t cpid = fork(); // 把 父进程 复制 一份 到子进程
if (-1 == cpid) {