想在两个进程间共享当前sqlite 的handle, 程序1一直跑着,试着把globalhandle通过共享变量的方式让程序2得到,可取到的总不对,部分代码如下,不知道错在哪求指点:
程序1
key_t id=ftok(path,0);
if (id==-1)
{
/* code */
perror("ftok error!\n");
}
if((shmid=shmget(id,4096,IPC_CREAT|0777))==-1){
perror("create shared memory error!\n");
}
ret=sqlite3_open("123.db",&globalHandlex);
sqlite3* handle = (sqlite3 *)shmat(shmid,0,0);
handle = globalHandlex;
程序2
key_t id=ftok(path,0);
if (id==-1)
{
/* code */
perror("ftok error!\n");
}
if((shmid=shmget(id,4096,IPC_CREAT|0777))==-1){
perror("create shared memory error!\n");
}
sqlite3* globalHandle=(sqlite3 *)shmat(shmid,0,0);
fprintf(stderr, "globalHandle 3:%x\n", globalHandle);
你只共享了一个指针吧……sqlite3 的数据结构应该挺复杂的。
你不说你的真实需求,所以我也不知道你该怎么解决你实际遇到的问题。