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 ]
|