message queue and signal notifiers

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • davidcollins001
    New Member
    • Mar 2008
    • 16

    message queue and signal notifiers

    Hi,

    I am trying to implement a blocked or synchronous method of message passing using signal interrupts. So far I have the following:

    server.c
    {
    msgget(queue)
    msgrcv (queue mtype)

    while(data to send) {
    msgsnd(data)
    kill(client, SIGUSR1)
    }

    close queue
    }

    client.c
    {
    sigaction(catch SIGUSR1)
    msgget(queue)
    msgsnd(queue mtype)

    while(data to read) {
    pause()
    printf(dadta)
    }
    }

    The way I can think of doing this is using sa_handler to call a function that reads from the queue when the signal is received. I feel like this isn't the best way to do it since I would have to globally define the structure that gets the data, along with the message queue id returned from msgget too.

    I am trying to learn how to use signals better and I would like some pointers on how to do this, or ideas that I can try.

    Thanks
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    Originally posted by davidcollins001
    Hi,

    I am trying to implement a blocked or synchronous method of message passing using signal interrupts. So far I have the following:

    server.c
    {
    msgget(queue)
    msgrcv (queue mtype)

    while(data to send) {
    msgsnd(data)
    kill(client, SIGUSR1)
    }

    close queue
    }

    client.c
    {
    sigaction(catch SIGUSR1)
    msgget(queue)
    msgsnd(queue mtype)

    while(data to read) {
    pause()
    printf(dadta)
    }
    }

    The way I can think of doing this is using sa_handler to call a function that reads from the queue when the signal is received. I feel like this isn't the best way to do it since I would have to globally define the structure that gets the data, along with the message queue id returned from msgget too.

    I am trying to learn how to use signals better and I would like some pointers on how to do this, or ideas that I can try.

    Thanks
    I would use semaphore or a mutex to accompilish this instead of a signal.
    Your idea is good but You will have better control when u use the one which i specified.

    Raghuram

    Comment

    Working...