没有合适的资源?快使用搜索试试~ 我知道了~
首页Linux_Programming_posix_ipc.ppt
Linux_Programming_posix_ipc.ppt

为给兄弟们扫盲,从网上整理的一些东东,希望对大家有帮助 Shared Memory Message Queues Semaphores Real-Time Signals Clocks and Timers Asynchronous I/O
资源详情
资源评论
资源推荐

Topics
Shared Memory
Message Queues
Semaphores
Real-Time Signals
Clocks and Timers
Asynchronous I/O

Linux Programming
POSIX Shared Memory

POSIX shared memory (1)
A great way to communicate between processes
without going through expensive system calls.
Open a shared memory object:
shm_fd = shm_open(“acme”, O_CREAT |
O_RDWR, 0666);
A zero size /dev/shm/acme file appears.
Set the shared memory object size
ftruncate(shm_fd, SHM_SIZE);
/dev/shm/acme is now listed with the specified size.
If the object has already been sized by another process,
you can get its size with the fstat function.

POSIX shared memory (2)
Map the shared memory in process address space:
addr = mmap (0, SHM_SIZE, PROT_WRITE,
MAP_SHARED, shm_fd,
0);
Now we have a memory area we can use!
Lock the shared memory in RAM (best for real-time
tasks):
mlock(addr, SHM_SIZE);
Use the shared memory object!
Other processes can use it too.
剩余29页未读,继续阅读

















安全验证
文档复制为VIP权益,开通VIP直接复制

评论1