massage structure?
Hi,
I need some info to be past from one process to another. And my idea was to send a message and then a signal to notify the other process. In http://www.cs.cf.ac.uk/Dave/C/node25...00000000000000 it says: The structure below is an example of what this user-defined buffer might look like: struct mymsg { long mtype; /* message type */ char mtext[MSGSZ]; /* message text of length MSGSZ */ } So can I change this to: typedef struct msgbuf { int mSlots[5]; int mError[5]; char mtext[MSGSZ]; } message_buf; or is the struct unchangeble. The man in linux gives: the calling process allocates a structure of the following general form : struct msgbuf { long mtype; /* message type must be >0*/ char mtext[1]; /* message data */ } any idees? |
Yah You can change, but first member should be Long int ( mtype).
Speciality in Linux message Queues is that Mtype. It allows Multiplexing of messages into a message queue. But at the other end while you are reading you should use the same Format structure. Other wise logically you may face problems. I hope this clarifies your doubt. Bye, Eshwar. |
By the by what do u want to do really?
I didnt get what you are willing to do with that. Can you explain it a little? |
I want to send info from one process to another in this form:
struct msgbuf { int mSlots[5]; int mError[5]; char mtext[MSGSZ]; } message_buf; so I dont have to pack and sort to an string or char array. |
Ya you can send but add long mtype as the first element of your message.
Recieve that data at the other end with the same structure format. It has to work try it. bye, Eshwar. |
1 st method:
struct msgbuf{ long mtype; int mSlots[5]; int mError[5]; char mtext[MSGSZ]; } message_buf; or SEcond method: struct mymessage{ int mSlots[5]; int mError[5]; char mtext[MSGSZ]; }; struct msgbuf { long mtype; struct mymessage message; } message_buf; Use any of above two methods. But read the data in to the same format structure variable ( sturcture used for writing). |
If u have any questions ask me on tomorrow. Its late i am leaving.
bye, Eshwar. |
Thanks eshwar
|
Here's the message queue part of a program I wrote to switch on/off two LED's connected to a serial port. Maybe you can use this. Your thing sound similar to me. If you would like to see the entire program, just send me an e-mail through my forum profile, and I'll mail you back with the .tar.gz of the program attached.
It has one daemon process that sits waiting for a SIGUSR1 signal from the client program. The client process puts a message on the queue, and then kills the daemon with SIGUSR1, The signal handler of the daemon gets the message from the queue and sets/unsets the lines of the serial port. This way the daemon uses exactly 0% CPU when there's nothing to do. Code:
Note that: Code:
/* msgq.h */ Code:
/* msgq.c */ |
hko thats exacly what im doing.
|
Nice!
I received your e-mail and I've send you the tar.gz with the sources of the client and daemon programs. Hope you can use this. |
All times are GMT -5. The time now is 05:53 AM. |