shmat help
airsupply
airsupply at freebsdchina.org
Sat Feb 7 07:38:36 PST 2004
freebsd-hackers=A3=AC=C4=FA=BA=C3=A3=A1
=09
i am test shmat under freebsd 4.8 release(without undate),but a=
piece of simple code wont work.
code like this:
#include<stdio.h>
#include<machine/param.h>
#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/shm.h>
#include <unistd.h>
#define SHM_KEY 100
#define SHM_SIZE 1024
int main(int argc,char *argv[])
{
int shmid;
void *shmaddr1,*shmaddr2,*shmaddr3;
if(shmid=3Dshmget(SHM_KEY,SHM_SIZE,IPC_CREAT|0660)=3D=3D-1)
{
perror("shmget");
exit(-1);
}
printf("shmid: %d\n",shmid);
if(shmaddr1=3Dshmat(shmid,0,0)=3D=3D-1)
{
perror("shmat 1");
exit(-1);
}
printf("shaddr1:0x%.8x\n",shmaddr1);
if(shmaddr2=3Dshmat(shmid,0,0)=3D=3D-1)
{
perror("shmat 2");
exit(-1);
}
printf("shaddr2:0x%.8x\n",shmaddr2);
while(1);
return 0;
}
then i get error like this:
shmid: 0
shmat 1: Invalid argument
then i use ipcs,find that the shmid is not 0,but an integer=
number.
-bash-2.05b$ ipcs
Message Queues:
T ID KEY MODE OWNER GROUP
Shared Memory:
T ID KEY MODE OWNER GROUP
m 65536 100 --rw-rw-rw- airs wheel
Semaphores:
T ID KEY MODE OWNER GROUP
who can help me? who i can't use the shmid at shmat(shmid,0,0) ? =
=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=D6=C2
=C0=F1=A3=A1
=09=09=09=09
=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1airsupply
=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1airsupply at freebsdchina.org
=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A12004-02-07
More information about the freebsd-hackers
mailing list