semaphores

Hi,

I am wondering is there is any mean to see how many semaphores have been
open on a QNX (4.24) node … or anything else related to semaphores on QNX
(states, …)

Thanks a lot.

“Djibril NDIAYE” <djibril.ndiaye@opal-rt.com> wrote in message
news:b33f1k$7d2$1@inn.qnx.com

Hi,

I am wondering is there is any mean to see how many semaphores have been
open on a QNX (4.24) node … or anything else related to semaphores on
QNX
(states, …)

No, sorry.

Thanks a lot.

Djibril NDIAYE <djibril.ndiaye@opal-rt.com> wrote:

Hi,

I am wondering is there is any mean to see how many semaphores have been
open on a QNX (4.24) node … or anything else related to semaphores on QNX
(states, …)

No clean way.

Proc32 -e num_sem sets the maximum
qnx_osinfo( …, &osinfo, … );
osinfo.num_semaphores will tell you what that max has been set to (default 125)

If you loop doing a sem_create() until it fails, count how many you get,
subtract that from the total – you’ll know how many are in use. (Ugh).

Of course, don’t forget to sem_destroy() all those semaphores. :slight_smile:
(Or, exit the process that created them, that should destroy them all
automatically. Well, if they’re in local memory…they’re automatically
destroyed when the memory they are in is returned to the OS’s free pool.)

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

Thank you very much. That’s what I figured out. Just wanted to be sure.

“David Gibbs” <dagibbs@qnx.com> wrote in message
news:b33n20$ds1$1@nntp.qnx.com

Djibril NDIAYE <> djibril.ndiaye@opal-rt.com> > wrote:
Hi,

I am wondering is there is any mean to see how many semaphores have been
open on a QNX (4.24) node … or anything else related to semaphores on
QNX
(states, …)

No clean way.

Proc32 -e num_sem sets the maximum
qnx_osinfo( …, &osinfo, … );
osinfo.num_semaphores will tell you what that max has been set to (default
125)

If you loop doing a sem_create() until it fails, count how many you get,
subtract that from the total – you’ll know how many are in use. (Ugh).

Of course, don’t forget to sem_destroy() all those semaphores. > :slight_smile:
(Or, exit the process that created them, that should destroy them all
automatically. Well, if they’re in local memory…they’re automatically
destroyed when the memory they are in is returned to the OS’s free pool.)

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

“Djibril NDIAYE” <djibril.ndiaye@opal-rt.com> wrote in message
news:b33f1k$7d2$1@inn.qnx.com

Hi,

I am wondering is there is any mean to see how many semaphores have been
open on a QNX (4.24) node … or anything else related to semaphores on
QNX
(states, …)

Thanks a lot.

Well, technically, every semaphore has its own ID which is returned from
sem_init() call. We could write a little query wrapper like listed below:
I’v tried to run it, and Send returns ENOSYS status so usuall QNX4 way to
query info about Proc resources does not work :-/

Question 2 QSS gurus: why ? what is so special with semaphores ? AFAIU they
are kernel objects same as for example processess, proxies or timers. Or i’m
wrong not ?

typedef unsigned short semid_t;
struct seminfo {
/* … */
};

int sem_query(semid_t semid, struct seminfo *seminfo) {
struct {
struct _proc_sem send;
struct _proc_sem_reply reply;
} msg;
int rc;

memset(&msg, 0, sizeof(msg));

msg.send.type = _PROC_SEM;
msg.send.subtype = _PROC_SUB_QUERY;
msg.send.semid = semid;
msg.reply.status = ENOMSG;

rc = Send(PROC_PID, &msg.send, &msg.reply, sizeof(msg.send),
sizeof(msg.reply));
if ((rc != 0) || ((errno = msg.reply.status) != EOK)) {
return -1;
}

/* … */

return msg.reply.semid;
} /* sem_query */

// wbr

Ian Zagorskih <ianzag@megasignal.com> wrote:

Well, technically, every semaphore has its own ID which is returned from
sem_init() call. We could write a little query wrapper like listed below:
I’v tried to run it, and Send returns ENOSYS status so usuall QNX4 way to
query info about Proc resources does not work :-/
msg.send.type = _PROC_SEM;
msg.send.subtype = _PROC_SUB_QUERY;

Cute try :slight_smile: A quick look at the proc code shows it only responds to
ATTACH (sem_init) and DETACH (sem_destroy) subtypes for _PROC_SEM …

“John Garvey” <jgarvey@qnx.com> wrote in message
news:b34v4a$8ma$1@nntp.qnx.com

Ian Zagorskih <> ianzag@megasignal.com> > wrote:
Well, technically, every semaphore has its own ID which is returned from
sem_init() call. We could write a little query wrapper like listed
below:
I’v tried to run it, and Send returns ENOSYS status so usuall QNX4 way
to
query info about Proc resources does not work :-/
msg.send.type = _PROC_SEM;
msg.send.subtype = _PROC_SUB_QUERY;

Cute try > :slight_smile: > A quick look at the proc code shows it only responds to
ATTACH (sem_init) and DETACH (sem_destroy) subtypes for _PROC_SEM …

Ah… Well, according to QSS’s report related to “The future of QNX4”,
Proc32 will be stable and solid as a rock for ever and ever so guess no
way…

Thanks for info. I’ll try another way then :slight_smile:

// wbr

Ian Zagorskih <ianzag@megasignal.com> wrote in message
news:b34uv2$sdf$1@inn.qnx.com

Ah… Well, according to QSS’s report related to “The future of QNX4”,
Proc32 will be stable and solid as a rock for ever and ever so guess no
way…

Thanks for info. I’ll try another way then > :slight_smile:

FYI - I’ve put in the ability to query the number of semaphores into QNX4.
It should go out with the next release (not patch G).

-Adam

“Adam Mallory” <amallory@qnx.com> wrote in message
news:b3ddar$m8u$1@nntp.qnx.com

Ian Zagorskih <> ianzag@megasignal.com> > wrote in message
news:b34uv2$sdf$> 1@inn.qnx.com> …

Ah… Well, according to QSS’s report related to “The future of QNX4”,
Proc32 will be stable and solid as a rock for ever and ever so guess no
way…

Thanks for info. I’ll try another way then > :slight_smile:

FYI - I’ve put in the ability to query the number of semaphores into
QNX4.
It should go out with the next release (not patch G).

You mean the number of used semaphores ? Anyway, good to hear. Will it be
possibly to query a list of used semaphores ? If frankly I don’t know what
for exactly this might be usefull but as minimum a’la “sin sem” would be
nice.

ps: just while testing semaphores Proc32 API i occasionally destroyed some
other process’s semaphore (with id=0) and though all seems to be fine but
i’d like to know who had owned it before i did that :slight_smile:

// wbr

Ian Zagorskih <ianzag@megasignal.com> wrote in message
news:b3dd0r$cbv$1@inn.qnx.com

You mean the number of used semaphores ? Anyway, good to hear.

Yes, obviously - it’s the number of semaphores currently ‘created’ via
sem_init().

Will it be
possibly to query a list of used semaphores ? If frankly I don’t know what
for exactly this might be usefull but as minimum a’la “sin sem” would be
nice.

I’ll put it into the queue.

-Adam

ps: just while testing semaphores Proc32 API i occasionally destroyed some
other process’s semaphore (with id=0) and though all seems to be fine but
i’d like to know who had owned it before i did that > :slight_smile:

// wbr

“Adam Mallory” <> amallory@qnx.com> > wrote in message
news:b3ddar$m8u$> 1@nntp.qnx.com> …

Ian Zagorskih <> ianzag@megasignal.com> > wrote in message
news:b34uv2$sdf$> 1@inn.qnx.com> …


Ah… Well, according to QSS’s report related to “The future of QNX4”,
Proc32 will be stable and solid as a rock for ever and ever so guess no
way…

Thanks for info. I’ll try another way then > :slight_smile:

FYI - I’ve put in the ability to query the number of semaphores into

QNX4.

It should go out with the next release (not patch G).

Just came across this thread. Yes “sin sem” would be nice.

Rennie

Rennie Allen <rgallen@attbi.com> wrote:

“Adam Mallory” <> amallory@qnx.com> > wrote in message

Just came across this thread. Yes “sin sem” would be nice.

“sin sem” works.

Of course, it gives the output of “sin session”. :slight_smile:

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.