LinuxSA Mailing list archives

Index: [thread] [date] [subject] [author]
  From: Robert Wuttke <robert.wuttke@disc.com.au>
  To  : Jake Hawkes" <jake@eclectic.com.au>, "LinuxSA Mailing List <jake@eclectic.com.au>
  Date: Tue, 18 May 1999 16:57:06 +0930

Re: (c-code)writing and reading from pipes

Well as far as I can see your assumptions seem to be correct.

Write should return straight away with the amount of bytes written to the
pipe file. Straight away the read happens. B Could rarely get a chance as it
would have to be swapped in, made the active process between the write and
read code in A, there is a window, but is extremely slim.

As far as A is concerned (due to the nature of read/write pipes), the data
waiting there for the read is new data, it doesn't care where it came from.

I would suggest a timeout period and setjmp and longjmp (????!!!?? Check the
man pages). Or a packet header to identify that it came from me. Something
would have to be done to stop a from reading itself.

To be honest I would suggest using the separate pipe idea. You can then
handle the synch by yourself instead of hoping that the scheduler does what
you want...

I can't give you the code for several reasons:

1) No Linux box or C compiler in front of me 8-(
2) C is rusty (okay very rusty!)

I hope this helps.

Rob.

Disclaimer: This info may/may not help, it may/may not be correct. Oh
well................

-----Original Message-----
From: Jake Hawkes <jake@eclectic.com.au>
To: LinuxSA Mailing List <linuxsa@linuxsa.org.au>
Date: Tuesday, 18 May 1999 3:39 PM
Subject: PRO: (c-code)writing and reading from pipes


>
>there, hope the subject line is helpfull ;)
>
>
>ok, two progs (proc A and procB) want to communicate with each other via
>a pipe, or pipes. The communications is to be 2-way.
>
>here are the (relevant) code snippets...
>(error checking, #define removed)
>
>procA
>  pipe = open("/tmp/rip_pipe", O_RDWR);
>
>  count = write(pipe, buff, 2);
>
>  read(pipe, buff, 2));
>
>procB
>  pipe = open("tmp/rip_pipe", O_RDWR);
>
>while(1) {
>  FD_SET(pipe, &fdSet);
>  FD_ZERO(&fdSet);
>
>  select(pipe+1, &fdSet, NULL, NULL, NULL);
>
>  if(!FD_ISSET(pipe, &fdSet))
>     continue;
>
>  count = read(pipe, buff, 2);
>
>  /*logic stuff*/
>
>  count = write(pipe, buff, 2);
>} /* end while(1) */
>
>bash$> mkfifo /tmp/rip_pipe
>
>this is what I think is happening.
>
>  o   procA writes to the pipe
>       \--> the write is successfull (buffered is some magic kernel
>buffer ??)
>  o   procB isn't swapped in by the kernel, and so the select() doesn't
>get a chance         \--> or something....
>  o   procA reads the pipe
>       \--> the read is successfull, and the same data back as it wrote.
>
>As far as the reads and writes being successful, this is true. The bytes
>read and written have been checked, the data read is in fact the same as
>that written.
>
>Can anyone confirm/deny my guess as to what's happening?
>
>One alternative to this is to have 2 pipes (1 read and 1 write), but I'd
>like this solution better.
>
>If I haven't explained it well enough, I'd be glad to say it all again
>:).
>
>--
>
>Jake Hawkes, B. Eng (CSE)
>
>e-mail: jake@eclectic.com.au
>
>--
>Check out the LinuxSA web pages at http://www.linuxsa.org.au/
>To unsubscribe from the LinuxSA list:
>  mail linuxsa-request@linuxsa.org.au with "unsubscribe" as the subject
>
>

-- 
Check out the LinuxSA web pages at http://www.linuxsa.org.au/
To unsubscribe from the LinuxSA list:
  mail linuxsa-request@linuxsa.org.au with "unsubscribe" as the subject


Index: [thread] [date] [subject] [author]
Return to the LinuxSA Mailing List Information Page