Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

shmat for attaching shared memory segment

When I looked through the man pages of shmat. It is described as the primitive function of the API is to attach the memory segment associated wih shmid it to the calling process' address space .

The questions I have are the following.

  • The term attach looks generic to me. I find difficulties in understanding what is the underlying acivity that attach refers to.?
  • What it means by mapping a segment of memory?
like image 744
Vivek Maran Avatar asked Oct 22 '22 03:10

Vivek Maran


1 Answers

Use it as char *ptr=shmat(seg_id,NULL,0); It attaches the created segment id by function shmget() with the process which contains this above code.

seg_id is the segment id of newly created segment NULL means the Operating System will take care of the starting address of the segment on user's behalf 0 is flag for read/write both

Whenever a process attaches to shared memory then it must be detached so that another process can access it by attaching to that segment (if the locking mechanism of resources is present.)

to detach : shmdt(ptr);

like image 167
Omkant Avatar answered Oct 26 '22 23:10

Omkant