ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
hello,
i want to send the pid of a processus through message queue... it's a program that c program that sends information to another program, that will use this pid to send back informations. but the pid sent and received are never the same, and I don't know how I could make it so?
if i have to give you my code; let me know..
thank you
AFAIK, message queues are pretty much for pthreads only. Since I think you are using fork(), I am thinking you really want to use a pipe to send data from the child to the parent.
it's communication interprocessus.. i don't know if utilising forks or something like that it could be done... all i need to do it's to send the pid of a process to a 'process that it's always listening and sends replies to the appropriate processus in fonction of the pid,
thank you.
mario
I think I feel your usage of babelfish. It is quite confusing.
As for your problem, are doing the standard C syscall fork() to spawn the client process, or are they independently run as separate apps? If you are doing fork(), then use pipe() to create a pair of file descriptors, one for reading and the other for writing. If they are separate apps, like a web browser - web server pair, than you need to use sockets.
Do you mean, you send for example "1234", and on the other end of the queue you receive some different number?
Then you have something wrong in your sending and/or receiving code obviously.
Do I understand correctly that you want to send the PID so the receiver knows where to send the reply?
Then I imagine something like sending the PID as the normal 'payload' of the message, and mark the message back with the PID in the "mtype" field of your "struct msgbuf".
But depending on your intentions, I think in your case a TCP- of file system-socket would be more suitable.
Quote:
Originally Posted by tuxdev
AFAIK, message queues are pretty much for pthreads only.
No, that's not the case. IIRC message queue's were invented a considerable number of years before threads.
hello
I do not use babelfish at all, but it's confusing for me, therefore i write it in a way not very clear; please apologize.
I may not use tcp or sockets, I have to use and ipc method, in this case I am using message queues, and i don't have time to try shared memory or other method at this stage so I must stick with it.
I want to do exactly what you said; I want to send the PID of a program c called 'the client' to a program c called 'the server', the server collects the data it has to and then sends the reply.
I hope i made myself clear now? didn't I?
may I show you the code of my 'client and 'server'? i am really stuck and can't do the rest of my code.
thank you
It looks like you need sockets to do this kind of IPC properly.
Hko: I am aware that message queues dated before pthreads, and is really what pipes and sockets are. However, I got the impression that POSIX message queues were made for use with pthreads.
the messages are sent from a tty window to another... do you understand? i log on on the linux box, and launch the server.
then i do a alt-f2 log on, then launch a client, then launch alt-f3 log on and launch another client etc, and these consoles have to communicate with each other.
does this require sockets? sockets aren't the concatenation of ip address with port number? just wondering?
and that's not all; I also need some sort of coordination it means that i may not do something if another client is doing the same thing.
to be fully complete; this program it's the management of a golf tournament. a server keeps track of the points and performances of the players aka the clients.
the coordination part means that if a client is playing at a 'hole', no other client may access that hole.
thank you.
Last edited by mariogarcia; 06-15-2006 at 06:37 PM.
what your client program is doing, is to send client's pid to server and to receive the message sent by server and see whether the client pid and the pid sent by server are same and you r not receiving the same pid at client side. i think this is your problem.
but first you need to send the received pid by server to the client,
your server program is not sending the received pid so how can client determine what is the pid it received from server.
i have to send the pid of the client to the server.. so that the server knows who to reply to since there are going to be several clients connected to the same server and the server needs to know who to address a message.
the other thing i need to know is how to store the struct received, from the client the server receives a struct via msgrcv(); i need to use that struct.. how do can i use it? put it in a table? let's say a cell by client.. ie: client connected : 1 corresponds to tab[1] etc,
i'thank you for the code, i'll work on them.
I really think that you should scrap POSIX message passing here because this app looks a lot like the client/server relationship between a web server and a web browser. This kind of program should really be able to run from two separate computers. POSIX message passing can only occur within the same computer, and the server and client must be related through fork() or pthread_create(). The use of this program I see is a caddy with a PDA logging the golfers progress through the game, and the data is sent to the server to prevent collisions, as well as generate up-to-the-minute reports that can be used on TV or the internet.
i have to send the pid of the client to the server.. so that the server knows who to reply to since there are going to be several clients connected to the same server and the server needs to know who to address a message.
the other thing i need to know is how to store the struct received, from the client the server receives a struct via msgrcv(); i need to use that struct.. how do can i use it? put it in a table? let's say a cell by client.. ie: client connected : 1 corresponds to tab[1] etc,
i'thank you for the code, i'll work on them.
Hko , what do you mean " mark the message back with the PID in the mtype field of struct msgbuf " ? U mean put the PID in the message field of struct msgbuf and also in the type field of msgbuf ? What 's the point of that ?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.