[lkml]   [2003]   [Jan]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: shmat problem
Doug, thanks for the reply. I've set SHM_RND in the call and used
"__attribute__ ((aligned(4096)))" during the the declaration of variable
(as shown below) such that it is aligned on a page boundary. I'm porting
code that was
written for a Unix system to Linux and the example shown below is how the
code is
implemented on Unix.

The example included executed correctly on :
mandrake - ? (Can't remember, but it was an old version)

but fails to work on:
redhat - 2.2.14-5.0
debian - 2.2.9
mandrake - 2.4.19-16mdk

We are currently working on mandrake - kernel 2.4.19-16mdk.


Example program:

#include <stdio.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <errno.h>

#define SHM_MODE (SHM_R | SHM_W)

union {
long IN[2048];
} global01_ __attribute__ ((aligned(4096)));

int main(void) {
int shmid;
char *shmptr;

if ( (shmid = shmget(IPC_PRIVATE, sizeof(global01_), SHM_MODE)) < 0){
printf("shmget error: %d %s\n",errno, strerror(errno));

if ( (shmptr = shmat(shmid, &global01_, SHM_RND)) == (void *) -1)
printf("shmat error: %d %s\n",errno, strerror(errno));
printf("shared memory attached from %x to %x\n",
shmptr, shmptr+sizeof(global01_));

if (shmctl(shmid, IPC_RMID, 0) < 0)
printf("shmctl error: %d %s\n",errno, strerror(errno));


Protect your PC - get VirusScan Online

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2005-03-22 13:32    [W:0.033 / U:3.140 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site