Howdy,
I wrote a DTrace script [1] to dump shared memory calls, and for some
reason the value returned in arg1 (the shared memory identifer) of
fbt::shmget:return doesn''t match the value returned by a simple C
program [2] that calls shmget:
$ dtrace -s shm.d
operation key shmid size flags CPU Wall Time
shmget 0 0 1048576 932 585000 613900
$ ./shm
Called shmget(): key: 0 size: 1048576 shmid: 268435534
Called shmat(): data: ff100000 shmid: 268435534
Called shmdt(): data: ff100000
The size and flags look correct, but the shmid is not quite right
(based on the sample program, it should be 268435534). Does anyone
happen to see anything wrong with my DTrace script? Based on the docs,
it looks like the return value should be in arg1, and it also looks
like the shmget() kernel routine returns the shmid back to the caller
(at least this is what I devised by reading through shm.c).
Thanks for any insight,
- Ryan
--
UNIX Administrator
http://prefetch.net
[1] shm.d
#pragma D option quiet
dtrace:::BEGIN
{
/* operation key shmid size flags cpu wall */
printf("%-10s %-10s %-10s %-10s %-10s %-10s %-10s\n",
"operation",
"key",
"shmid",
"size",
"flags",
"CPU", "Wall
Time");
}
fbt::shmget:entry
{
self->key = arg0;
self->size = arg1;
self->flags = arg2;
self->shmgettimestamp = timestamp;
self->shmgetvtimestamp = vtimestamp;
}
fbt::shmget:return
/ self->shmgettimestamp /
{
/* operation key shmid size flags cpu wall */
printf("%-10s %-10x %-10x %-10d %-10d %-10d %-10d\n", probefunc,
self->key, arg1,
self->size, self->flags,
vtimestamp -
self->shmgetvtimestamp,
timestamp - self->shmgettimestamp);
}
[2] shm.c
include <stdio.h>
#include <unistd.h>
#include <sys/ipc.h>
#include <sys/shm.h>
int main(int arg, char **argv)
{
key_t key = 0;
int shmid = 0;
int size = 1024 * 1024;
char *data;
/* Create a 1MB shared memory segment */
shmid = shmget(key, size, 0644 | IPC_CREAT);
printf("Called shmget(): key: %d size: %d shmid: %d\n", key, size,
shmid);
/* Attach to the shared memory segment */
data = shmat(shmid, (void *)0, 0);
printf("Called shmat(): data: %x shmid: %d\n", data, shmid);
/* Detach from the shared memory segment */
shmdt(data);
printf("Called shmdt(): data: %x\n", data);
return(0);
}