shrd_mem

download shrd_mem

If you can't read please download the document

description

asdasd

Transcript of shrd_mem

#include#include#include#include#include#include #include key_t key;main(){int i;int status;int shm_id;int *shrd_mem_ptr;// pointer for accessing shared memorykey = ftok("./", 'x');pid_t id;shm_id= shmget(key, 6* sizeof(int), IPC_CREAT|0666);// here we are loavtin memory space for 6 integers// we can allocate mem. for any other data type.shrd_mem_ptr = (int *)shmat(shm_id, NULL, 0);// it returns a void pointer to the shared memory location// but we want to operate on integers so we type cast the pointer returnedid = fork();if (id == 0){printf("values read by child process from shared memory are: \n ");for(i=0; i