- 论坛徽章:
- 0
|
汗,坛子里找不到vxworks版,就发这了。。
就是想用sdlib里的两个函数sdCreate( ) 和 sdOpen( )来创建共享内存,具体是这样的
进程rtp1用sdCreate成功创建一块共享区域,结束后rtp2用sdOpen打不开这块内存,求高手解。。。
- //rtp1.c
- #include "sdLib.h"
- #include "vxWorks.h"
- #include "stdio.h"
- #include "stdlib.h"
- #define SD_NAME "share buffer"
- int main()
- {
- SD_ID id = NULL;
- typedef struct {
- int a;
- int b[3];
- }buffer;
- buffer *pbuffer;
- id = sdCreate(SD_NAME, 0,sizeof(buffer), (off_t)NULL, SD_ATTR_RW|SD_CACHE_OFF, (void**)&pbuffer);
- if(NULL == id)
- {
- printf("%d error when create share data in rtp\n",id);
- exit(1);
- }
- printf("%d\n",id);
- sdDelete(id, 0);
- return 0;
- }
复制代码- //rtp2.c
- #include "vxWorks.h"
- #include "errno.h"
- #include "stdio.h"
- #include "stdlib.h"
- #include "sdLib.h"
- #define SD_NAME "share buffer"
- int main()
- {
- SD_ID rtp_id2 = NULL;
- typedef struct {
- int a;
- int b[3];
- }buffer;
- buffer *pbuffer = (buffer *)malloc(sizeof(buffer));
- rtp_id2 = sdOpen(SD_NAME, SD_LINGER, 0, sizeof(buffer), (off_t)NULL, SD_ATTR_RW|SD_CACHE_OFF, (void **)&pbuffer);//此时sdOpen返回NULL
- if(NULL == rtp_id2)
- {
- printf("error when open share data \n");
- exit(0);
- }
- printf("rtp2(%d) share data address is %x.",rtp_id2,(unsigned long)pbuffer);
- return 0;
- }
复制代码 |
|