Mailing List Archive

msgget key?
At Larry's suggestion, I'll try here...

Perl 5.001 on my AIX 3.2 box accepts the following nicely:

$MSGQID = msgget(pack("L",0x0abcdef),(IPC_CREAT | 00660)) or die;
$MSGQID = msgget("filename",(IPC_CREAT | 00660)) or die;

as shown by ipcs:

IPC status from /dev/mem as of Tue Oct 24 12:07:45 1995
T ID KEY MODE OWNER GROUP
q 12289 00000000 -Rrw-rw---- dcheney staff
q 16386 00000000 -Rrw-rw---- dcheney staff

but note that the KEY is always zero. types.h shows typedef long key_t;
so I'd expect the first msgget to work. Since it doesn't, the second
is more like one would expect if libc's ftok() was being used... but still
no KEY.

How can one use the same KEY to connect multiple processes to the same
message queue? Pointers?

As I'm not subscribed (yet:) , please e-mail directly... thanks!

-----------------------------------------------------------------------------
David J. Cheney Electronic Commerce Services
(512) 838-8017 (T/L 678) IBM Networked Application Services
http://www.austin.ibm.com/~dcheney 11400 Burnet Road, Austin, TX 78758
-----------------------------------------------------------------------------
Re: msgget key? [ In reply to ]
According to David Cheney:
> $MSGQID = msgget(pack("L",0x0abcdef),(IPC_CREAT | 00660)) or die;
> $MSGQID = msgget("filename",(IPC_CREAT | 00660)) or die;

The first parameter to all the System V IPC "get" functions (semget,
shmget, msget) should be a numeric value -- not a packed string, and
_definitely_ not a filename.

$MSGQID = msgget(0x0abcdef, (IPC_CREAT | 00660)) or die;

--
Chip Salzenberg, aka <chs@nando.net>
"Hey, it's the Miss Alternate Universe Pageant!"
-- Crow T. Robot, MST3K: "Stranded In Space"
Re: msgget key? [ In reply to ]
> The first parameter to all the System V IPC "get" functions (semget,
> shmget, msget) should be a numeric value -- not a packed string, and
> _definitely_ not a filename.
>
> $MSGQID = msgget(0x0abcdef, (IPC_CREAT | 00660)) or die;

I've been getting questions internally (to HP) about this too. Does
the IPC extension have ftok?

Jeff
Re: msgget key? [ In reply to ]
I've used the following hack...

my ($junk, $INO, $junk) = stat("$BASE/bin/@_");
my ($KEY) = 0xdc000000 | $INO; # arbitrary, my initials
$MSGQID = msgget($KEY,(01000|0660)) or ... # IPC_CREAT | rw-rw----

to create the message queue using a KEY that is the inode # of the program
that will process messages on the queue. I guess its pretty close to what
ftok() does (though I haven't looked at the code) and ftok() docs say that
you can create your own KEY any way you like. I guess the only thing to
watch out for is collisions.

A nifty little kicker is a piece I wrote to replace the KEY with the program
name in ipcs(1) output, thus showing queue status for each program. First,
create a KEY to filename reverse hash:

# map program inode -> program name for later pasting into ipcs KEY field
opendir(BIN,$BIN); @PGMS = readdir(BIN);
foreach (@PGMS) {
$KEY = map_filename_to_key($_);
$PGMS{$KEY} = sprintf("%-18.18s",$_);
}

Then, get the ipcs output in a string, replace, and print:

$Q = `ipcs -qa | grep 0xdc &`;
foreach (keys(%PGMS)) { $Q =~ s|$_|$PGMS{$_}|s; } # paste pgm names
print "T ID KEY MODE OWNER GROUP CREATOR CGROUP CBYTES QNUM QBYTES LSPID LRPID STIME RTIME CTIME\n$Q\n";

Neat!

suggestions > dcheney@austin.ibm.com :)

Dave
----

Jeff Okamoto wrote:
>
> > The first parameter to all the System V IPC "get" functions (semget,
> > shmget, msget) should be a numeric value -- not a packed string, and
> > _definitely_ not a filename.
> >
> > $MSGQID = msgget(0x0abcdef, (IPC_CREAT | 00660)) or die;
>
> I've been getting questions internally (to HP) about this too. Does
> the IPC extension have ftok?
>
> Jeff
>

-----------------------------------------------------------------------------
David J. Cheney Electronic Commerce Services
(512) 838-8017 (T/L 678) IBM Networked Application Services
http://www.austin.ibm.com/~dcheney 11400 Burnet Road, Austin, TX 78758
-----------------------------------------------------------------------------
Re: msgget key? [ In reply to ]
> > The first parameter to all the System V IPC "get" functions (semget,
> > shmget, msget) should be a numeric value -- not a packed string, and
> > _definitely_ not a filename.
> >
> > $MSGQID = msgget(0x0abcdef, (IPC_CREAT | 00660)) or die;
>
> I've been getting questions internally (to HP) about this too. Does
> the IPC extension have ftok?

I'll put it into the next version when I get 'A Round Tuit'.


-- Jack Shirazi, JackS@slc.com