Unix进程间通信比较
2018-05-09 本文已影响0人
超哥__
通信方式
共享内存 (速度最快、需要进程处理同步)
命名管道
消息队列
SOCKET
RPC
同步方式:
文件锁
信号量
MONITOR
共享内存
System V IPC | UNIX mmap | POSIX IPC | |
---|---|---|---|
create memory area in operating system table | ftok shmget | open lseek write | shm_open lseek write |
attach memory to virtual address space | shmat | mmap | mmap |
detach memory from virtual address space | shmdt | munmap | munmap |
remove memory area from operating system table | shmctl | close unlink | close shm_unlink |
信号量
POSIX named semaphores | POSIX unnamed semaphores | System V semaphores | |
---|---|---|---|
create semaphore | sem_open | sem_init | semget |
initialize | at creation time | at creation time | semctl |
P (…) | sem_wait | sem_timedwait | sem_trywait |
sem_wait | sem_timedwait | sem_trywait | semop |
V (…) | sem_post | sem_post | semop |
read value | sem_getvalue | sem_getvalue | semctl |
remove semaphore | sem_close sem_unlink | sem_destroy | semctl |
boost/interprocess