server.cとclient.cの2つのプロセスがあり、POSIXメッセージキューを介して通信しています。クライアントはキューにメッセージを送信し、mq_notifyはサーバーにメッセージがキューに追加されたことを通知します。その後、シグナルハンドラーはメッセージを受信して処理します。しかし、正しく動作させることができません。client.cからメッセージを追加しても、シグナルハンドラーは送信されません(ただし、server.cからメッセージを追加すると、ハンドラーが設定されます)。サーバーは引き続きクライアントからキューに入れられたメッセージを受信できますが、何らかの理由で、server.cのmq_notifyで使用されるハンドラーを開始しません。誰かがこれが何であるかについて何か考えがありますか?それぞれの側からの関連するサンプルコードは次のとおりです。
client.c
/* queue has already been created, this opens it*/
msgq_id = mq_open(MSGQOBJ_NAME, O_RDWR);
if (msgq_id == (mqd_t)-1) {
perror("In mq_open()");
exit(1);
}
/* sending the message -- mq_send() */
mq_send(msgq_id, packet.mesg_data, strlen(packet.mesg_data), msgprio);
/* closing the queue -- mq_close() */
mq_close(msgq_id);
server.c
void handler()
{
/*for now it just prints that the signal was recieved*/
}
/*i opening the queue -- mq_open() */
msgq_id = mq_open(MSGQOBJ_NAME, O_RDWR);
if (msgq_id == (mqd_t)-1) {
perror("In mq_open()");
exit(1);
}
int main(){
.
.
.
.
/*Set up to be notifed when the queue gets something in it*/
signal(SIGUSR1, handler);
sigevent.sigev_signo = SIGUSR1;;
if(mq_notify (msgq_id, &sigevent) == -1)
{
if(errno == EBUSY)
printf("Another process has registered for notifications.\n");
_exit (EXIT_FAILURE);
}
//strcpy(packet2.mesg_data, "Hello world!");
//mq_send(msgq_id, packet2.mesg_data, strlen(packet2.mesg_data), 0);
while(1)
{
/*wait to be notified*/
}
.
.
.
}
これは、それらが別々のプロセスであることに関係がありますか?