How do you detach an array of strings from shared memory? C

Posted by Tim on Stack Overflow See other posts from Stack Overflow or by Tim
Published on 2012-11-09T04:35:20Z Indexed on 2012/11/09 5:00 UTC
Read the original article Hit count: 153

Filed under:
|
|
|
|

I have:

int array_id;
char* records[10];

// get the shared segment
if ((array_id = shmget(IPC_PRIVATE, 1, 0666)) == -1) {
            perror("Array Creating");
}

// attach
records[0] = (char*) shmat(array_id, (void*)0, 0);
if ((int) *records == -1) {
     perror("Array Attachment");
}

which works fine, but when i try and detach i get an "invalid argument" error.

// detach
int error;
if( (error = shmdt((void*) records[0])) == -1) {
      perror(array detachment);   
}

any ideas? thank you

© Stack Overflow or respective owner

Related posts about c

    Related posts about arrays