#include
#include
#include
int main(int argc, char **argv)
{
int segment_id;
char *shared_mem;
const int size = 5096; // in bytes
//create shared mem.
segment_id = shmget(IPC_PRIVATE, size, S_IRUSR|S_IWUSR);
//attach the shared mem. to the process in Write Read mode.(0 argument)
shared_mem = (char * )shmat(segment_id, NULL, 0);
//write the data to the shared memory.
sprintf(shared_mem, "This is the shared memory example coded by Eren Golge. Regards!!");
//read the data from
printf("*%s \n", shared_mem );
//detach the segment from process
shmdt(shared_mem);
//delete the shared mem. segment form memory
shmctl(segment_id, IPC_RMID, NULL);
printf("End of code");
return 0;
}
I'll share all my work to learn technologies while also I am studying. Thus, if you wanna learn programming let's keep up with me. I might have some mistakes about explanations or codes, if you realize please warn me to correct it, remember I am new learner too.
27 Şubat 2011 Pazar
IPC (Interprocess Communication) implementation example.
This example code illustrates the basic implementation of IPC mechanism that is provided by POSIX API.
Kaydol:
Kayıt Yorumları (Atom)
Hiç yorum yok:
Yorum Gönder