[fpc-pascal] Linux IPC (SHM) : Getting Strange Value for shm_nattch (# of attachements)
Tom__G
tom at guilleminot.org
Tue Oct 13 16:48:33 CEST 2009
Hi,
I try to get number of processes attached to a specific shared memory
segment.
So I read the shmctl record to retrieve this into shared memory :
type TShmid_ds = record
shm_perm: TIPC_Perm; Permissions
shm_segsz: cint; Segment size
shm_atime: time_t; Last access time
shm_dtime: time_t; Last detach time
shm_ctime: time_t; Create time
shm_cpid: ipc_pid_t; Creator PID
shm_lpid: ipc_pid_t; Last operation PID
shm_nattch: Word; Number of attachments <--<< !
shm_npages: Word; Number of pages
shm_pages: Pointer; ?
attaches: pointer; ?
end;
I just created a simple function that I added to example found here :
http://www.freepascal.org/docs-html/rtl/ipc/shmctl.html
http://www.freepascal.org/docs-html/rtl/ipc/shmctl.html
...
Function Get_Nb_Proc(ID : longint) : word;
Var
data : TSHMid_ds;
shmctl_result : integer;
begin
shmctl_result := shmctl (shmid,IPC_STAT, at data);
writeln ('shmctl_result :', inttostr(shmctl_result));
If shmctl_result=-1 then
begin
writeln ('Error : shmctl :',fpgeterrno);
halt(1);
end
else
Get_Nb_Proc:=data.shm_nattch;
end;
...
I tested and attached 1, 2 or 3 max processes to the segment. But I always
get strange high value while 'ipcs -m' shows me correct number of
attachements :
tom at debian:~/TESTS$ ipcs -m
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x53030001 24379392 tom 666 100 2
tom at debian:~/TESTS$ ./shmtool1
Shared memory -1 exists. Opening as client
shmctl_result :0
Number of Processes Attached to Shared Memory Segment 24379392 : 40920
<--<< !
Press to Close
Does anyone know what happens ?
Thanks
Tom
--
View this message in context: http://www.nabble.com/Linux-IPC-%28SHM%29-%3A-Getting-Strange-Value-for-shm_nattch-%28--of-attachements%29-tp25874304p25874304.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
More information about the fpc-pascal
mailing list