[plug] Perl 'tie' equivalent for Linux files (not a Perl question)
Craig Ringer
craig at postnewspapers.com.au
Fri Oct 4 16:05:03 WST 2002
> Is there any such way or workaround to achieve this kind of thing? If not,
> then my question is also still answered.
You can achieve something very like this using a named pipe (mkfifo
mypipe) and a (perl in this case) script like
while ($noexit) {
open(MYFIFO,"mypipe")
or die("Error opening named pipe \"mypipe\": $!");
do_write_stuff_to_fifo();
close(MYFIFO);
}
though I seem to remember (did this ages ago) that it'll need a SIGPIPE
handler installed that restarts the script when the reading process
closes the FIFO. Sorry, I really don't remember. However, as an example
this works:
$ mkfifo test
$ dd if=/dev/urandom of=test bs=1k count=1 &
[1] 789
$ cat test
så¡;í¶ÏÜUxÀ\¬ýU¸ÍÜúÃ*°qãý¦×¤LtR³3ÌÌ#n»:ûærÙÖÊxSWaNcªs_ä&']býÊ¡Ðî=WÛ
ÕÑ3´¤8¯ U_¡ Ô GE Õ®ØZ_ Â
ÇI ðJX×Ôͨ ýð³¾çÑôV2Z5½5å½â£>Ò^² P )-åÊIG6^ã ö÷¾] î-òE Võ ,¸ÆMÏRæ+
N¼XÆ R-'Ù¦
d}iqñðl2,îa*VE âÑáÎ!ªù\m¡ú]]nQ'ÛÈÞaÄçA±ôÌ=ðÞD)Íë{¹@ÁÙIò_¬uXkZÜO¦
;èØØHf#8Q$²tóö¡nÁB¾âEDh}?3#<ЧÄESQöç].æVìPÊzKú5 ìÄQæÊØxjÄæ
zgGÅl E¦ÚálFæMÔRºÄMêFªë±± !ùºÏgÚ
þýªb}Ñ0Áj[$ÿÍ<Â.îáQ}ý]cl¬÷ôü-
TöÐJÎOÜô!¬v¨ªÆ5+f#öéõÛ©zÓ/?É^ª
fr´Æì[øìó¶§C¥P¤Û¥è®ò"Ô89 S¦ØÉjú$u©,4hjC¥IV Z] §;2 ©¢t³#jæôÛÔoÉiøèF¾bPÆÔÁ
üDÐ,|®_8jã²ßKÔU»vø=á,È3íB?)qÙÏ+oÒV,SìÙµ?½p¼£¾±»$Ð>3HÏG·½^±º>ýÝâðK«óýiéÆÅ1)êÊéÇs¨à'E"K[ÙRÚë¾2
ûÎsÈoF\T¿/r
N^!n+èÌeìí1Ü./LªÁèìbäOáÀøñ5FF£Ï5öy\uåz´~wï{ª¡CÌ
õ;`ÓÓ«OM×Tä¹¹y½öÄP;àtYEUçÍ,yÍ8ãÚCÿ¶Íä8S٧ŷÍGûÍ!/Xë|!è»?Ý«
ëéìW)gôòµQz{ùERð9+êEKT̲«Ë}'(ÓíºB¤yT !ÏM¼E*Âc
[1]+ Done dd if=/dev/urandom of=test bs=1k count=1
It is important to note that this does NOT work exactly like a file -
AFAIK you can't seek in data from a named pipe, and SIGPIPE signals may
be sent to the reading process when the writing process closes the pipe,
or vice versa. Still, its one possible avenue and one I've used
successfully in the past for a few things.
--
Craig Ringer
GPG Key Fingerprint: AF1C ABFE 7E64 E9C8 FC27 C16E D3CE CDC0 0E93 380D
-- if it ain't broke, add features 'till it is. (or:)
while (! broken) { features ++ ; broken = isBroken(features) }
More information about the plug
mailing list