LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-15-2006, 10:56 AM   #1
mariogarcia
Member
 
Registered: Sep 2005
Distribution: debian, solaris 10
Posts: 202

Rep: Reputation: 31
send PID through message queue


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
 
Old 06-15-2006, 12:00 PM   #2
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
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.
 
Old 06-15-2006, 02:54 PM   #3
mariogarcia
Member
 
Registered: Sep 2005
Distribution: debian, solaris 10
Posts: 202

Original Poster
Rep: Reputation: 31
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
 
Old 06-15-2006, 03:15 PM   #4
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
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.
 
Old 06-15-2006, 03:21 PM   #5
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Originally Posted by mariogarcia
but the pid sent and received are never the same
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.

Last edited by Hko; 06-15-2006 at 03:22 PM.
 
Old 06-15-2006, 03:41 PM   #6
mariogarcia
Member
 
Registered: Sep 2005
Distribution: debian, solaris 10
Posts: 202

Original Poster
Rep: Reputation: 31
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
 
Old 06-15-2006, 04:41 PM   #7
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
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.
 
Old 06-15-2006, 06:36 PM   #8
mariogarcia
Member
 
Registered: Sep 2005
Distribution: debian, solaris 10
Posts: 202

Original Poster
Rep: Reputation: 31
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.
 
Old 06-16-2006, 02:10 PM   #9
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
Just read this tutorial for some explanation of what sockets are and how to use them.
http://beej.us/guide/bgnet/
 
Old 06-19-2006, 04:17 AM   #10
varun_shrivastava
Member
 
Registered: Jun 2006
Distribution: Ubuntu 7.04 Feisty
Posts: 79

Rep: Reputation: 15
hi mario,


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 sent a mail to you with programs attached.


bye
VARUN
 
Old 06-19-2006, 07:25 AM   #11
mariogarcia
Member
 
Registered: Sep 2005
Distribution: debian, solaris 10
Posts: 202

Original Poster
Rep: Reputation: 31
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.
 
Old 06-19-2006, 10:57 AM   #12
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
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.
 
Old 06-20-2006, 10:47 AM   #13
varun_shrivastava
Member
 
Registered: Jun 2006
Distribution: Ubuntu 7.04 Feisty
Posts: 79

Rep: Reputation: 15
Quote:
Originally Posted by mariogarcia
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 m not able to understand what you mean

please make it clearer
 
Old 06-20-2006, 03:08 PM   #14
mariogarcia
Member
 
Registered: Sep 2005
Distribution: debian, solaris 10
Posts: 202

Original Poster
Rep: Reputation: 31
i need a way to modify the data sent through the message queue and send it back to the client that sent it
 
Old 08-18-2006, 09:51 AM   #15
aral
Member
 
Registered: Aug 2005
Posts: 115

Rep: Reputation: 15
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 ?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
qmail queue -- can't send mail to anywhere -- please help me b:z *BSD 2 07-12-2005 08:30 AM
send to all that connect to same msg queue feetyouwell Programming 1 11-01-2004 12:41 PM
Qmail Message Queue dadepfan Linux - Software 0 07-22-2004 03:54 PM
send-queue problem packet drop jorgen Linux - Networking 0 02-07-2004 02:04 PM
Send Queue Growing - Why does this happen? oswald21 Linux - Networking 0 08-13-2003 01:33 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration