extending by using procedurallanguage C : problems accessing shared memory

From: Feite Brekeveld <f(dot)brekeveld(at)osiris-it(dot)nl>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: extending by using procedurallanguage C : problems accessing shared memory
Date: 2002-12-16 17:49:20
Message-ID: 3DFE1220.9020006@osiris-it.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


Hi,

I'm having some trouble extending postgresql with some C-functions.

Although I have done some tests with examples that work fine I have
trouble in a function in which I wat to access data that is in shared
memory.

Functionalty is split into 2 functions because the ti_shmmav fuction is
also used by other programs.

Trouble is in the second function where I use the shmat call . Is there
a way to do this ?

When running :

select shmmav(2785298, 1); // the large number is the segment id

I get the following message:

server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.

* There is data in the shared memory and I've tested it using a
perlscript to perform the same kind of operation

Some hints would be very helpful,

thanks ,

Feite Brekeveld
----------------------code snippet
--------------------------------------------

double *shmmav(int *shmid, int *period)
{
double *ret = palloc(sizeof(double));

*ret = ti_shmmav(shmid , period);
return ret;
}

double ti_shmmav(int *shmid, int *period)
{
double ret;
PREC *pprec;
int i = 0;
double total = 0.0;

pprec = (PREC *)shmat( *shmid, NULL, SHM_RDONLY);
if ( pprec == NULL) {
fprintf(stderr, "Error attaching SHM: id %d\n", *shmid);
}
while (i < *period) {
total += pprec[i].c;
i++;
}

ret = total / (float)(*period);
shmdt(pprec);

return ret;
}

------------------------------------------------------------------

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ken Godee 2002-12-16 18:01:13 Re: Copy/foreign key contraints
Previous Message Fernando Nasser 2002-12-16 17:31:50 Re: JDBC - Open Office