Messages : what are used for
Messages : what are used for
hello all, i read some docs about message passing, but i did not find a real using example.
are messages used to help sharing ressources between processes ?
if i develop a monolitic kernel, do i need messages ?
can u give me some real examples of message passing ?
thank's all
are messages used to help sharing ressources between processes ?
if i develop a monolitic kernel, do i need messages ?
can u give me some real examples of message passing ?
thank's all
Re:Messages : what are used for
Hi,
Here's an example from the GCC library documentation:
Please note that there's hundreds of different ways messaging could be implemented, and there'd be (mostly minor) differences with how each OS's messaging is used.
Cheers,
Brendan
Messaging (or IPC in general) is used for communication between processes/threads, and sometimes the kernel. Here "communication" might include controlling resource sharing, keypresses, video data, syncronization, notifications (something started, something changed, something ended), etc - basically anything the software wants to use it for.aladdin wrote: are messages used to help sharing ressources between processes ?
No, but you probably do need some form of IPC (Inter-Process Communication). On Unix this normally means "pipes", but modern versions of Unix support messaging too (although they might call it "Datagram Socket Operations"). Alternatively, software could use shared files or shared memory to communicate.aladdin wrote: if i develop a monolitic kernel, do i need messages ?
Look for any source code designed for Windows (or any other OS that uses messages) ....aladdin wrote: can u give me some real examples of message passing ?
Here's an example from the GCC library documentation:
Code: Select all
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/un.h>
#define SERVER "/tmp/serversocket"
#define MAXMSG 512
int
main (void)
{
int sock;
char message[MAXMSG];
struct sockaddr_un name;
size_t size;
int nbytes;
/* Remove the filename first, it's ok if the call fails */
unlink (SERVER);
/* Make the socket, then loop endlessly. */
sock = make_named_socket (SERVER);
while (1)
{
/* Wait for a datagram. */
size = sizeof (name);
nbytes = recvfrom (sock, message, MAXMSG, 0,
(struct sockaddr *) & name, &size);
if (nbytes < 0)
{
perror ("recfrom (server)");
exit (EXIT_FAILURE);
}
/* Give a diagnostic message. */
fprintf (stderr, "Server: got message: %s\n", message);
/* Bounce the message back to the sender. */
nbytes = sendto (sock, message, nbytes, 0,
(struct sockaddr *) & name, size);
if (nbytes < 0)
{
perror ("sendto (server)");
exit (EXIT_FAILURE);
}
}
}
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Re:Messages : what are used for
ok, thank you for these information, but, what is the content of messages, is there some protocols? or it is up to the OS to decide ?
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Messages : what are used for
Everything will depend up to the OS designer. Most of the time, you desing an interface and a way to map interface methods (code & arguments) into a datastructure...
Re:Messages : what are used for
Hi,
For the OS's services (file systems, device drivers, etc) the messaging protocols used should be the same for all software of the same type, and these would be determined by the OS.
For communication between third party software there is no need for an OS defined protocol (whoever writes it can decide), however there's often a few "OS reserved messages" that the OS uses for special events (e.g. for telling the thread/process to terminate, alarms/timeouts, etc).
Cheers,
Brendan
There are no protocols (unless you want a clone of some other OS). In general the software that receives the message determines the format of the message, as it must be able to understand it.aladdin wrote: ok, thank you for these information, but, what is the content of messages, is there some protocols? or it is up to the OS to decide ?
For the OS's services (file systems, device drivers, etc) the messaging protocols used should be the same for all software of the same type, and these would be determined by the OS.
For communication between third party software there is no need for an OS defined protocol (whoever writes it can decide), however there's often a few "OS reserved messages" that the OS uses for special events (e.g. for telling the thread/process to terminate, alarms/timeouts, etc).
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Messages : what are used for
You may find guidelines to structure your messages in something like SunRPC, DCE, etc. Those are middleware for procedure/method call across a channel (the message abstraction offered by the system being a possible channel).
Another interresting reference is python's b-encoding which is easy enough to decode and will provide a good substrate for passing variable-length strings, list of elements, or sets of elements.
Now, much will depend on the underlying limitations of your own scheme. If you wish transparent confirmation of message reception with an asynchronous messaging system, you need to code a protocol with acknowledgments. If you wish to overcome the limited size of messages, you may need to split large message and thus require a protocol that tells the receiver how many messages are left, etc.
In a general way, you write an _interface definition_ of your service, telling what message are valid and how they're encoded and then you write client & server code according to that definition.
Another interresting reference is python's b-encoding which is easy enough to decode and will provide a good substrate for passing variable-length strings, list of elements, or sets of elements.
Now, much will depend on the underlying limitations of your own scheme. If you wish transparent confirmation of message reception with an asynchronous messaging system, you need to code a protocol with acknowledgments. If you wish to overcome the limited size of messages, you may need to split large message and thus require a protocol that tells the receiver how many messages are left, etc.
In a general way, you write an _interface definition_ of your service, telling what message are valid and how they're encoded and then you write client & server code according to that definition.
Re:Messages : what are used for
ok, i ll give an example and correct me if i'm wrong
suppose we have a microkernel a memory allocator and another process (called P)
P needs to allocate some memory so it use a function which send a message to the kernel telling it it wants specified size of memory
kernel will redirect the message to mem allocator which will allocate memory and send a reply containing the address of allocated area
suppose we have a microkernel a memory allocator and another process (called P)
P needs to allocate some memory so it use a function which send a message to the kernel telling it it wants specified size of memory
kernel will redirect the message to mem allocator which will allocate memory and send a reply containing the address of allocated area
Re:Messages : what are used for
That would be one possible use, yes.
Another would be synchronization. Say, for example, you have wo messaging primitives, send() and recv(), where send() will wait until the recipient recv()s the message, and recv() will wait until a message is recieved. If thread A send()s to process B, which recv()s it, the two process will have effectively performed a rendevous.
Assuming two asynchronous primitives, pass() and check(), you can still synchronize by having process A pass() a message, then loop on a series of short sleep()s followed by a check() to see when process B replies. If you want to contiue processing in A, you simply omit the sleep() and perform your processing within the loop instead. In practice, it would be useful to support both synchronous and asynchronous message-passing, and allow the programmer of each thread to decide which to use when.
Another would be synchronization. Say, for example, you have wo messaging primitives, send() and recv(), where send() will wait until the recipient recv()s the message, and recv() will wait until a message is recieved. If thread A send()s to process B, which recv()s it, the two process will have effectively performed a rendevous.
Assuming two asynchronous primitives, pass() and check(), you can still synchronize by having process A pass() a message, then loop on a series of short sleep()s followed by a check() to see when process B replies. If you want to contiue processing in A, you simply omit the sleep() and perform your processing within the loop instead. In practice, it would be useful to support both synchronous and asynchronous message-passing, and allow the programmer of each thread to decide which to use when.
Re:Messages : what are used for
What's the difference between sincron and asincron msg pass? if you don't want to explain, can you tellme some web where i found some info about?
Thanks.
Thanks.
Re:Messages : what are used for
sync messages are those who require a reply, in this case, the sender (process/task ...) is blocked waiting for the ACK (reply).
async messages are those who wait for reply, the message is sent, and the process continue its job.
you can compare it to some network protocols :
UDP = async
TCP = sync
async messages are those who wait for reply, the message is sent, and the process continue its job.
you can compare it to some network protocols :
UDP = async
TCP = sync
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Messages : what are used for
Wrong. Asynchronous message passing means that you have no idea whether the message has been receive or not when the call terminates. But if your system is correctly designed, the target will eventually receive and process the message, while UDP may lose messages without any possible way for you to detect the loss.aladdin wrote: you can compare it to some network protocols :
UDP = async
TCP = sync
For instance, a messaging mechanism could keep the message in a queue if space remains and block the caller if no room is left in the queue. If the queue size >1, this makes the mechanism asynchronous but still not lossy.
Now, TCP vs synchronized ... TCP is connection-oriented and it is a bytestream. It's thus completely different from a messaging system since it cannot preserve messages bounds.
Re:Messages : what are used for
Asynchronous is like placing a memo on somebody's monitor. Synchronous is like waiting at the monitor to tell him something.
With asynchronous you can either check for memo's or place a memo somewhere, but you can't be sure that either a memo will be there or that somebody else will react to the memo and send you a reply back.
Synchronous is like having a conversation, one says something, then the other, and so forth. It also means that you need to have conversational matter and that both parties may not quit without telling the other (for computers never go bored waiting). On the other hand, with asynchronous the other "person" needs to keep his own context and he can't be sure that you'll keep sending him memo's.
With asynchronous you can either check for memo's or place a memo somewhere, but you can't be sure that either a memo will be there or that somebody else will react to the memo and send you a reply back.
Synchronous is like having a conversation, one says something, then the other, and so forth. It also means that you need to have conversational matter and that both parties may not quit without telling the other (for computers never go bored waiting). On the other hand, with asynchronous the other "person" needs to keep his own context and he can't be sure that you'll keep sending him memo's.