java linuc进程间通信对比
读《unix网络编程第二卷进程通信》
1.管道
2.消息队列
3.信号量
4.共享内存
这些在java中怎么实现?
如果是管道,参考http://www.iteye.com/topic/156804,看下面代码,
注意把“注意这里!!!!!!!!”的i换成256实验一下效果
#include "unpipc.h"void client(int, int), server(int, int);intmain(int argc, char **argv){ int pipe1[2], pipe2[2]; pid_t childpid; Pipe(pipe1); /* create two pipes */ Pipe(pipe2); if ( (childpid = Fork()) == 0) { /* child */ Close(pipe1[1]); Close(pipe2[0]); server(pipe1[0], pipe2[1]); exit(0); } /* 4parent */ Close(pipe1[0]); Close(pipe2[1]); client(pipe2[0], pipe1[1]); Waitpid(childpid, NULL, 0); /* wait for child to terminate */ exit(0);}