Is there any way, within a c program, of finding out if someone else has
a file open that you have open?
I know qtalk checks the open count on the serial port when it is
invoked, but I am not sure if this is a terminal thing or a file thing.
I can’t even remember how it is done…
What I want to do is open an mqueue in /dev/mqueue and see if anybody
else has it open (in the hope that if they do they will read if I
write).
Any clues anybody?
Function dev_info (I think it is) returns a structure. One member is an
open count but it is not documented in the man page. Take a look at the
system header file declaring dev_info (I believe it’s sys/dev.h)
Donald Backstrom wrote:
Is there any way, within a c program, of finding out if someone else has
a file open that you have open?
I know qtalk checks the open count on the serial port when it is
invoked, but I am not sure if this is a terminal thing or a file thing.
I can’t even remember how it is done…
What I want to do is open an mqueue in /dev/mqueue and see if anybody
else has it open (in the hope that if they do they will read if I
write).
Any clues anybody?
Dean Douthat <ddouthat@faac.com> wrote:
Function dev_info (I think it is) returns a structure. One member is an
open count but it is not documented in the man page. Take a look at the
system header file declaring dev_info (I believe it’s sys/dev.h)
But, all of the dev_* functions only deal with devices that are managed
by Dev. Unfortunately, message queues are managed by Mqueue – and I
don’t think it handles those messages. (Well, it probably does, but
not usefully – it would reply with ENOSYS.)
dev_info() [or similar] is what is being used by qtalk for the serial port.
To my knowledge, there is no easy way to get this information.
The ugly way is to try and parse the output of “sin fd”, looking for
your queue.
Is there any way, within a c program, of finding out if someone else has
a file open that you have open?
What I want to do is open an mqueue in /dev/mqueue and see if anybody
else has it open (in the hope that if they do they will read if I
write).
Hm… maybe… if you do a mq_getattr(), it won’t tell you if anyone has
it open… byt the mq_recvwait entry will tell you how many processes are
block on read (if the queue is empty), and if you know that your reader will
be in this state… it might be an accurate enough hint.
-David
QNX Training Services
dagibbs@qnx.com