Hallo zusammen!
Auf <
http://openbook.galileocomputing.de/unix_guru/node393.html> habe
ich was interessantes gefunden. Doch war ich gleich verwundert, weil ich
mir dachte "Machste erst mal das Programm "Two" um mal zu sehen, was
passiert, wenn Programm "One" noch gar kein Shared Memory gesetzt hat.
Aber es kommt kein Fehler<staun>.
#include <sys/ipc.h>
#include <sys/shm.h>
#define MAXMYMEM 30
int main(){
shID = shmget(2404, MAXMYMEM, IPC_CREAT | 0666);
if (shID >= 0) {
/* nun holen wir den Speicher */
myPtr = static_cast<char*>(shmat(shID, 0, 0));
if (myPtr==(char *)-1) {
//perror("shmat");
std::cout<<"\nSHARE IDABASE ERROR";
std::cout.flush();
} else {
/* Speicher ist zugreifbar: füllen! */
for (i=0; i<MAXMYMEM; i++) {
myPtr[i] = 'A'+i;
std::cout<<"\nSHARE IDABASE "<< myPtr[i];
std::cout.flush();
}
//getchar(); /* Warte mal auf eine Taste */
/* gebe den Speicher auf */
shmdt(myPtr);
}
} else { /* shmget lief schief */
std::cout<<"\nSHARE IDABASE ERROR 1";
std::cout.flush();
}
}
Die Ausgabe:
SHARE IDABASE A
SHARE IDABASE B
SHARE IDABASE C
SHARE IDABASE D
SHARE IDABASE E
SHARE IDABASE F
SHARE IDABASE G
SHARE IDABASE H
SHARE IDABASE I
SHARE IDABASE J
SHARE IDABASE K
SHARE IDABASE L
SHARE IDABASE M
SHARE IDABASE N
SHARE IDABASE O
SHARE IDABASE P
SHARE IDABASE Q
SHARE IDABASE R
SHARE IDABASE S
SHARE IDABASE T
SHARE IDABASE U
SHARE IDABASE V
SHARE IDABASE W
SHARE IDABASE X
SHARE IDABASE Y
SHARE IDABASE Z
SHARE IDABASE [
SHARE IDABASE \
SHARE IDABASE ]
SHARE IDABASE ^
Wie kann denn das? Wieso bekomme ich denn eine Auasgabe, wie man sie
erwartet, wenn Programm "One" einen Shared Memory-Bereich eingerichtet
hätte?
Mit Gruß
Heinz-Mario Frühbeis