regarding socket & mssage queue

Are all reads and writes passing the correct amount of data, you may get partial reads/writes as the pipe becomes full.

I recommend putting a loop round each read and write so if the API returns less, you go back for the remainder you are expecting.

while (len)
{
    int i=read(fd,p,len);
    if (i < 0) { perror("read"); break; }
    if (i == 0) break;
    p+=i;
    len-=i;
}

and

while (len)
{
    int i=write(fd,p,len);
    if (i < 0) { perror("write"); break; }
    if (i == 0) break;
    p+=i;
    len-=i;
}

Sir, As u told me i had used strace -ppid
and here is the output what I am getting........
it is showing me two pids for a same process........and when I used to strace to them then its showing me following outputs .........

outputs::::::::
[root@localhost New Folder]#strace -p3153
Process 3153 attached - interrupt to quit
write(5, "\0i, I am fine101010\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 100
<unfinished ...>
Process 3153 detached
[root@localhost New Folder]# strace -p3152
Process 3152 attached - interrupt to quit
wait4(-1,

Why is it sitting in wait4()? looks like it thinks the child process should be dead and it's trying to reap it, so it has fallen out of the select loop.

The two pids are one for the main process and another for the child process, which is what we were trying to achieve.

I had put wait in parent ....so that parent will not terminate untill child will not free its resources........If I will not use wait in parent, the parent will terminate and child will be running.........

Yes that's fine, but it's not going to be waiting for input in select if it's blocking in wait4.

your main process should be

pid_child=fork();

if (!pid_child) 
{ 
     exit(run_child());
}

while (running)
{
      set up fd_sets
      select
      do reads,writes and other stuff
}

kill(pid_child,SIGINT);
waitpid(pid_child...)

you had send me this code.....but I didnt able to understand why you had used p+=i; where p is a char string ......
moreover I am getting more difficulties with code...i.e through pipe read end I am not able to read the data.....
when i check for strace -ppid its showing continously polling (for parent) with select
and child witing for msgrcv()......

Say you want to receive 4096 bytes, but the first read only gets 1024, the next read you do wants to start from where you left off.

Add debugging code to trace what the program is doing.

Use a debugger to step through the code line by line if you have to.

Sir,
now facing problem while using socket comm. and select........my message queue and pipe part is working ....no problem at that side....
my application is continously reading through pipe but when socket comes into picture (my socket is server side (tcp/ip))....it reads only once through socket .....and I had to start client again.

this means that polling is again started with new socket connection......not as per read call.......
so how to implement....tell some steps to follow??????
please guide

Excellent, good to hear.

Again, do this step by step. You should

(a) have the socket in non-blocking mode.

(b) add lots of tracing and debugging code so you can print out what is actually happening

(c) you *must* cater for partial reads, where you try and read 100 bytes and only get 50.

You should be able to have many very long running client connections.

sir,

that I am doing correctly.....

I am only having one client attached to the server.....(acc to my system).

first of all I starts my server.....and from another system I starts client ....now connection got established after that client tries to send sone data...my server recieves it correctly(I am using client fd to collect what server is sending)....after that when client tries to send some more packets or data then it fails ......means its polls only once.....after that it doesnt read any packet......
please tell me which file drscriptor should i use to read and send data......

In pseudo code-

int fd_server=socket(AF_INET,SOCK_STREAM,0);
bind(fd_server,...
listen(fd_server,..

when socket fd_server is readable do

fd_client=accept(fd_server,...)

then use the fd_client to send() and recv() on, and finally close() when you are finished with that client.

While you have one client, another client can come in and try and connect, so hence you need to work out how to accept and manage multiple client connections each with their own file descriptor.

Thanks Sir,
my both -----Socket part and Pipe & message queue part are working correctly.....
thanks a lot for ur precious help.....

Excellent, I am glad to hear of your success. :slight_smile:

Hi All,

I am doing the same task of sending and receiving the messages through SOCKETS and writing back to files using message ques.

Please guide me how to get rid :

msgrcv : Invalid argument.

I am using message queues: msgsnd and msgrcv,

I am able to send through msgsnd and receive through msgrcv, but at times i get the belo error.

msgrcv : Invalid argument.

Snippet from the man page.

int msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg);
  The msgrcv() function will fail if:

     [EINVAL]           The msqid argument is not a valid message queue iden-
                        tifier.

                        The message queue was removed while msgrcv() was wait-
                        ing for a message of the requested type to become
                        available on it.

                        The msgsz argument is less than 0.

One of these is the culprit.