, ' .
. 8.1 ', .
| 䳿 |',| . ³ ' || . || |',| , , . ', , , .
|| ', , :
shmget ', , || || ||;
shmat || ' , ||;
shmdt ' || |,|;
||, shmctl || , ' .
ϳ , ', , ' , || ' || , .
shmget :
shmid = shmget(key, size, flag);
size . || || . ', , || , || ||, || , ||, |',| . || || ', , || . || '. ' . , ' ' ||.
ϳ ' shmat:
virtaddr = shmat(id, addr, flags);
id - || , addr - , '. |',| ( ' || || addr). addr |',| , .
|
|
' shmdt:
shmdt(addr);
addr - ', || shmat.
shmctl:
shmctl(id, cmd, shsstatbuf);
|| cmd, , . || |',| ', . |,| . ', ', |,| , ||, , , . , shmget , || , || || , '. ' .
int main()
{
int segment_id;
char *shared_memory;
struct shmid_ds shmbuffer;
int segment_size;
const int shared_segment_size = 0x6400;
segment_id = shmget(IPC_PRIVATE, shared_segment_size, IPC_CREAT|IPC_EXCL|S_IRUSR|S_IWUSR);
shared_memory = (char*) shmat(segment_id, 0, 0);
printf("\n ' : %p", shared_memory);
shmctl(segment_id, IPC_STAT, &shmbuffer);
segment_size = shmbuffer.shm_segsz;
printf("\n : %d", segment_size);
sprintf(shared_memory, "Hello, World!");
shmdt(shared_memory);
shared_memory = (char*)shmat(segment_id, (void*)0x5000000, 0);
printf("\n ' : %p", shared_memory);
printf("\n %s\n\n", shared_memory);
shmdt(shared_memory);
shmctl(segment_id, IPC_RMID, 0);
return 0;
}