pipe of size 1
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > pipe of size 1




Pages (2): [1] 2 »   Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    pipe of size 1  
Tejas Kokje


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-24-04 07:48 AM

Hello,

How to make pipe of size 1. I mean what I want is writer
always write one value. Whenever writer wants to write another,
it over writes the old value in pipe.

Reader always reads one value.

How can i implement them using UNIX pipes

Tejas Kokje





[ Post a follow-up to this message ]



    Re: pipe of size 1  
Lev Walkin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-24-04 07:48 AM

Tejas Kokje wrote:
> Hello,
>
> How to make pipe of size 1. I mean what I want is writer
> always write one value. Whenever writer wants to write another,
> it over writes the old value in pipe.
>
> Reader always reads one value.
>
> How can i implement them using UNIX pipes

...by switching to using the shared memory.

--
Lev Walkin
vlm@lionet.info





[ Post a follow-up to this message ]



    Re: pipe of size 1  
Michael B Allen


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-24-04 07:48 AM

On Sat, 24 Jul 2004 00:08:26 -0400, Lev Walkin wrote:
 
>
> ...by switching to using the shared memory.

How does shared memory allow you to make a UNIX pipe with a buffer size
of only 1?

Mike





[ Post a follow-up to this message ]



    Re: pipe of size 1  
Lev Walkin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-24-04 07:48 AM

Michael B Allen wrote:
> On Sat, 24 Jul 2004 00:08:26 -0400, Lev Walkin wrote:
>
> 
>
>
> How does shared memory allow you to make a UNIX pipe with a buffer size
> of only 1?

By creating a cognitive leap in your head forcing you to use the appropriate
tools for the task.

--
Lev Walkin
vlm@lionet.info





[ Post a follow-up to this message ]



    Re: pipe of size 1  
Tejas Kokje


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-28-04 11:19 PM

Actually the platform on which I am working doesn't seem to
have shared memory support.(Even simple shared memory programs
didn't run :-( ). I am working on Linksys WRT54GS router
which runs Linux.

Regards,
Tejas Kokje





On Sat, 24 Jul 2004 01:18:17 -0700, Lev Walkin wrote:
> Michael B Allen wrote: 
>
> By creating a cognitive leap in your head forcing you to use the appropria
te
> tools for the task.






[ Post a follow-up to this message ]



    Re: pipe of size 1  
Michael B Allen


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-28-04 11:19 PM

On Sat, 24 Jul 2004 04:18:17 -0400, Lev Walkin wrote:
 
>
> By creating a cognitive leap in your head forcing you to use the
> appropriate tools for the task.

Ahh, based on this and your other posts I see clearly now. I haven't
been around in a while. I guess everyone else has already reached the
point where they know to just ignore you.





[ Post a follow-up to this message ]



    Re: pipe of size 1  
Lev Walkin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-28-04 11:19 PM

Tejas Kokje wrote:
> Actually the platform on which I am working doesn't seem to
> have shared memory support.(Even simple shared memory programs
> didn't run :-( ). I am working on Linksys WRT54GS router
> which runs Linux.

Okay, here's the problem: you want the receiver to fetch only
the last status value from another process.

You cannot do it using pipes, because the pipes interface is not
designed to handle such case. And you cannot do it using shared
memory support, because your hardware has a Linux which is
compiled without SysV IPC support enabled.

You could do the following:
1. Recompile the Linux, or somehow else obtain a kernel with
System V IPC services enabled. This would be the easiest from
a programming standpoint: shared memory support is quite easy
to implement.

2. If the first one is not an option, there is the trick:
open a file descriptor (literally, a descriptor of a file), and
delete the file. Then lock it using write lock (lockf, flock
or fcntl(2) interfaces). Provide a client (child?) with the
copy of this descriptor (dup() or another open() of the file
before it is being deleted). Let it try to lock the file
too. Then, if you need to communicate status, simply write
something in the beginning of the file (pwrite(2) or
fseek() + write()). Make sure the size is small enough to
guarantee atomicity. After writing, unlock the file and lock
it again.

Meanwhile, the client will obtain the lock on the file during
the window between the sender unlocks the file and locks it
again. While holding a lock, client should read the first N (1?)
bytes of the file using pread() or fseek()+pread(), and then
unlock the file and try to lock it again.

This should solve the task of supplying the status to your
client. The locks aren't doing anything to "synchronize"
this atomic process: they are needed only to communicate
that the new data is available in that file.

3. Use signals: if you need to communicate a status, you
typically don't have to supply the whole 1b value to the
receiver: it is often enough to have a handful of status
codes. Use different signals (like, SIGUSR1 and SIGUSR2)
to communicate different status codes.


P.S. I am assuming you need to communicate status codes
between two applications or an instances of one application,
or something like that. If what you really need is just to
use pipe() + have a way to overwrite 1 byte, please talk to
Michael B Allen, which certainly has more solid experience
answering precisely the question which was asked.

[vbcol=seagreen]
> On Sat, 24 Jul 2004 01:18:17 -0700, Lev Walkin wrote:
> 


--
Lev Walkin
vlm@lionet.info





[ Post a follow-up to this message ]



    Re: pipe of size 1  
Chuck Dillon


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-28-04 11:19 PM

Tejas Kokje wrote:

> Hello,
>
> How to make pipe of size 1. I mean what I want is writer
> always write one value. Whenever writer wants to write another,
> it over writes the old value in pipe.
>
> Reader always reads one value.
>
> How can i implement them using UNIX pipes
>
> Tejas Kokje

An alternative to using shared memory would be to use a semaphore
(assume they are enabled) as a mailbox.

-- ced

--
Chuck Dillon
Senior Software Engineer
NimbleGen Systems Inc.





[ Post a follow-up to this message ]



    Re: pipe of size 1  
Lev Walkin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-28-04 11:19 PM

Chuck Dillon wrote:
> Tejas Kokje wrote:
> 
>
>
> An alternative to using shared memory would be to use a semaphore
> (assume they are enabled) as a mailbox.

1. time-bound waiting on semaphores is not portable.
2. there is no simple mechanism to wait on socket/pipe events
and semaphore status changes at the same time. (except using
threads or forking off processes and then supplying semaphore
conditions back using [drum...] the pipe again).

--
Lev Walkin
vlm@lionet.info





[ Post a follow-up to this message ]



    Re: pipe of size 1  
Chuck Dillon


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-28-04 11:19 PM

Lev Walkin wrote:
> Chuck Dillon wrote:
> 
>
>
> 1. time-bound waiting on semaphores is not portable.
> 2. there is no simple mechanism to wait on socket/pipe events
> and semaphore status changes at the same time. (except using
> threads or forking off processes and then supplying semaphore
> conditions back using [drum...] the pipe again).
>

You've lost me.  The OP wants a single byte mailbox shared between
processes.  A semaphore can provide such a mechanism without the need
for a time bound wait or a socket/pipe.

-- ced


--
Chuck Dillon
Senior Software Engineer
NimbleGen Systems Inc.





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 05:22 AM.      Post New Thread    Post A Reply      
Pages (2): [1] 2 »   Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register