Re: Help! Shared memory is getting deleted after process is killed
- From: gil_hamilton@xxxxxxxxxxx
- Date: 20 Jul 2006 04:28:18 -0700
Anuradha wrote:
After killing my process, when I do ipcs, I am unable to see the shared
memory created. Also, I am getting the errno as ENOENT, which means
that it has created it since key does not exist.(#define ENOENT 2
/* No such file or directory */)
It works fine for me; the shm segment stays around after the process is
killed. Test program below.
GH
#include <stdio.h>
#include <errno.h>
#include <sys/shm.h>
int do_shm(void)
{
static key_t key;
int shmId;
void *shmBase;
if ((key = ftok("/tmp", 87654321)) == (key_t)-1)
{
printf("ftok failed - %s\n", strerror(errno));
return 0;
}
if ((shmId = shmget(key, 1, IPC_CREAT | IPC_EXCL | 0600)) == -1)
{
if (errno == EEXIST)
{
printf("Key %x exists -- try shmget without CREAT\n", key);
shmId = shmget(key, 1, 0);
}
if (shmId == -1)
{
printf("shmget failed - %s\n", strerror(errno));
return 0;
}
}
else
printf("Key %x created\n", key);
if ((shmBase = shmat(shmId, NULL, 0)) == (void *)-1)
{
printf("Unable to attach to shared memory - %s\n",
strerror(errno));
return 1;
}
printf("Attached to key %x\n", key);
return 1;
}
int main(int ac, char **av)
{
if (!do_shm())
return 1;
pause();
return 0;
}
.
- Follow-Ups:
- References:
- Help! Shared memory is getting deleted after process is killed
- From: Anuradha
- Re: Help! Shared memory is getting deleted after process is killed
- From: "Nils O. Selåsdal"
- Re: Help! Shared memory is getting deleted after process is killed
- From: Anuradha
- Help! Shared memory is getting deleted after process is killed
- Prev by Date: Re: Help! Shared memory is getting deleted after process is killed
- Next by Date: Re: ZModem communication within C Applications?
- Previous by thread: Re: Help! Shared memory is getting deleted after process is killed
- Next by thread: Re: Help! Shared memory is getting deleted after process is killed
- Index(es):
Relevant Pages
|