Yea, I guess it is easier when you can see the code. This is what I'm using, and it keeps giving me "shm_open failed ..." with errno being ENOENT.
Code:
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/mman.h>
size_t shmsize = 10;
int shmfd;
const char *shmname = "/tmp/shmtest";
unsigned *shmaddr;
int main()
{
shmfd = shm_open(shmname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IWGRP | S_IRGRP | S_IWOTH | S_IROTH);
if(shmfd > 0)
{
if(ftruncate(shmfd, shmsize) != -1)
{
shmaddr = (unsigned *)mmap(0, shmsize, PROT_READ | PROT_WRITE, MAP_SHARED, shmfd, 0);
if(shmaddr != MAP_FAILED)
{
memset(shmaddr, 0, shmsize);
memcpy(shmaddr, "hello", 5);
printf("Coppied \"hello\" to shared memory.\n");
}else
{
printf("mmap failed errno %d.\n", errno);
}
}else
{
printf("ftruncate failed errno %d.\n", errno);
}
}else
{
printf("shm_open failed errno %d.\n", errno);
}
return 0;
}