I have these 2 simple programs using shared memory in linux.
Data client:
FILE *fp;
fp = fopen("mem.share", "r");
if (fp<=0){
cout<<"Error, cannot open memory link file"<<endl;
return -1;
}
int shmid;
fscanf (fp, "%d", &shmid);
fprintf(fp, "%d", shmid);
fclose(fp);
cout<<"Using the file share index #"<<shmid<<endl;
uint8_t* buffer = (uint8_t*)shmat(shmid, NULL, 0);
if (buffer<=0){
cout<<"Error, cannot link memory"<<endl;
return -1;
}
Data provider:
int shmid = shmget(IPC_PRIVATE, 140, 0666);
FILE *fp;
fp = fopen("mem.share", "w+");
fprintf(fp, "%d", shmid);
fclose(fp);
I run these two programs in this system, with no problem:
Armbian Buster with Linux 5.3.9-sunxi
/etc/os-release:
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
But, when i trie to run the programs in this system:
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
I got this result:
Using the file share index #524304
outstation: pthread_mutex_lock.c:81: __pthread_mutex_lock: Assertion `mutex->__data.__owner == 0' failed.
Aborted
These are the shared memory in the two systems (using ipcs -m) Armbian:
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x00000000 0 alfa 666 140 0
0x00000000 1 alfa 666 140 0
0x00000000 2 alfa 666 140 0
0x00000000 3 alfa 666 140 0
0x00000000 4 alfa 666 140 0
0x00000000 5 alfa 666 140 0
0x00000000 6 alfa 666 140 0
0x00000000 7 alfa 666 140 0
Raspbian:
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x00000000 0 root 666 140 0
0x00000000 32769 pi 666 140 0
0x00000000 65538 pi 666 140 0
0x00000000 98307 pi 666 140 0
0x00000000 131076 pi 666 140 0
0x00000000 163845 pi 666 140 0
0x00000000 196614 pi 666 140 0
0x00000000 229383 pi 666 140 0
0x00000000 262152 pi 666 140 0
0x00000000 294921 pi 666 140 0
0x00000000 327690 pi 666 140 0
0x00000000 360459 pi 666 140 0
0x00000000 393228 pi 666 140 0
0x00000000 425997 pi 666 140 0
0x00000000 458766 pi 666 140 0
0x00000000 491535 pi 666 140 0
0x00000000 524304 pi 666 140 0
Can anyone help-me to understand what I'm doing wrong? What is the diference between these two systems?
Thanks!
User contributions licensed under CC BY-SA 3.0