Linux共享内存进程间通信
这是我写的共享内存通信的程序,用了两个信号量,可以保证信息一条一条的发。
用下面两条命令编译和运行:
make -f makefile
./create_shm
这是我运行的结果:
jan@Jan:~$ make -f makefile
rm create_shm opr_shm print_shm
gcc create_shm.c -o create_shm
gcc opr_shm.c -o opr_shm
gcc print_shm.c -o print_shm
jan@Jan:~$ ./create_shm
create_shm:seccessfully created segment : 5341209
opr_shm:Segment attached at 0xb804f000
print_shm:segment attached at 0xb7ef1000
print:1 message send to print_shm
print:2 message send to print_shm
print:3 message send to print_shm
opr_shm:Segment detached
print:4 message send to print_shm
print_shm:Segment detached
jan@Jan:~$
Leave a comment