Mailing List Archive

Support open source code!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

tlug: perl daemons keeping me up past my bed time....




Hello,

	This is another one of those "a simple 5 minute perl hack"
many hours later.

I have a bunch of server programs that normally read in some data over
a serial port, tcp connection etc. For testing purposes, we can write
all this info to a file and play it back later. However, these files
can be 20-50MB, so they are normally gzipped. As it turns out, I often
run out of disk space when I need to gunzip them. In the best of all
worlds, the server processes would just read from stdin. No such luck.

So... as I was thumbing through the Perl Cookbook, I happened to
notice an entry "Making a Process look like a file with Named
Pipes". Bingo, thats what I need to do:

unCanIt: uncompresses a file and sends it through a named pipe

Usage: unCanIt [-h] -f file

Options:
        -h    This help
        -f    file to uncompress. Should be .Z, .gz or .bz2

This makes a named pipe in $TMPDIR and uncompresses a file through it.
It prints the name of the pipe to stdout.

Example:
        myProg `unCanIt -f somefile.gz`

This creates a name pipe, and writes the decompressed file to
it. Since it prints the name of the named pipe to stdout, myProg can 
just take that as an argument.


Simple. No problem. I can get it work if I just run it like:

unCanIt -f ~/arc/sysinfo2.1.tar.gz &
/tmp/unCanIt.16497 <--- this is from stdout of unCanIt
tar tvf /tmp/unCanIt.16497

If I have it in back ticks though, the whole thing hangs. I tried
forking, but no luck:

	make named pipe
	if(fork)
		print namedPipe
		exit
	else
		system("gzip -cd file.gz >> $namedPipe")
		unlink namedPipe

Doing:

	tar tvf `unCanIt -f ~/arc/sysinfo2.1.tar.gz` &

If I look with ps

    andy 16534 16533  0 02:56:22 ?        0:00 sh -c /usr/local/bin/gzip -cd /h/andy/arc/sysinfo2.1.tar.gz >> /tmp/unCanIt.165
    andy 16541 16011  0 02:59:04 pts/4    0:00 grep tar
    andy 16532     1  0 02:56:21 ?        0:00 /usr/local/bin/perl /h/andy/script/unCanIt -f /h/andy/arc/sysinfo2.1.tar.gz
    andy 16533 16532  0 02:56:21 ?        0:00 sh -c /usr/local/bin/gzip -cd /h/andy/arc/sysinfo2.1.tar.gz >> /tmp/unCanIt.165

A couple things I can't figure out here. Why do I have two process,
16533 and 16534, that seem the same? It looks like I have:

	16532 -> 16533 -> 16534

Where is my tar? When I kill the above, I suddenly have:

    andy 16551 16011  0 03:05:39 pts/4    0:00 tar tvf /tmp/unCanIt.16552

Confused....

Thanks,

	Andy
------------------------------------------------------------------
Next Technical Meeting: 12 December, 12:30 at Temple Univ. Japan
*NEW LOCATION* a map is available at http://www.tuj.ac.jp/maps.html
Next Nomikai: 15 January 1999, 19:30 Tengu TokyoEkiMae 03-3275-3691
------------------------------------------------------------------
more info: http://tlug.linux.or.jp                     Sponsor: PHT


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links