[uClibc] xScale shmctl funkiness
Wen Yang
weny at promise.com
Sun Feb 15 01:40:16 UTC 2004
Hi,
I tried to use shmctl(..., IPC_STAT, ...) to get the shm statistics
(struct shmid_ds) The shm_segsize seems always correct, but any
afterwards were messed up. And the shm_nattch was always reported as 1.
I tried with the native glibc based toolchain to compile my sample code,
and it just worked fine. One thing I noticed is the sizeof(struct
shmid_ds) is 84 for glic, but 64 for uClibc.
I am using uClibc 0.9-20. I checked the 0.9-21, it seems no change.
Anybody has this problem, or it is fixed?
Thanks!
Wen
---------
ps. The following is the sample code:
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <errno.h>
#include <unistd.h>
#define SVSHM_MODE (SHM_R | SHM_W)
static char _msg[256];
static void _printShmStat(struct shmid_ds * pShmStat)
{
sprintf(_msg, "Shm Stat:\n segSize: %d\n attTime: %s dttTime:
%s\
createTime: %s createPid: %d\n lastOpPid: %d\n numAttac: %d\n",
pShmStat->shm_segsz, ctime(&(pShmStat->shm_atime)),
ctime(&(pShmStat->shm_dtime)),
ctime(&(pShmStat->shm_ctime)),
pShmStat->shm_cpid, pShmStat->shm_lpid,
pShmStat->shm_nattch);
printf("%s", _msg);
}
int main(void)
{
pid_t pid = 0;
key_t key = -1;
int nShm = -1;
void * pShm = 0;
struct shmid_ds shmStat;
int nRet = -1;
printf("shmid_ds size: %d\n", sizeof(struct shmid_ds));
pid = fork();
if (pid != 0)
{
printf("fork() child process id %d\n", pid);
return 0;
}
pid = getpid();
key = ftok("/dev/islavista", 't');
if (key == -1)
{
printf("process %d ftok() failed - %s\n", pid,
strerror(errno));
return -1;
}
nShm = shmget(key, 4092, SVSHM_MODE | IPC_CREAT);
if (nShm == -1)
{
printf("process %d shmget() failed - %s\n", pid,
strerror(errno));
return -1;
}
printf("process %d shm id %d\n", pid, nShm);
printf("before attach\n");
nRet = shmctl(nShm, IPC_STAT, &shmStat);
if (nRet == -1)
{
printf("process %d shmctrl() failed - %s\n", pid,
strerror(errno));
return -1;
}
else
{
_printShmStat(&shmStat);
}
printf("after attach\n");
pShm = (void *)shmat(nShm, NULL, 0);
if (pShm == (void *)-1)
{
printf("process %d shmat() failed - %s\n", pid,
strerror(errno));
return -1;
}
while (1)
{
sleep(5);
nRet = shmctl(nShm, IPC_STAT, &shmStat);
if (nRet == -1)
{
printf("process %d shmctrl() failed - %s\n",
pid, strerror(errno));
return -1;
}
else
{
_printShmStat(&shmStat);
}
}
return 0;
}
More information about the uClibc
mailing list