Xref: utzoo comp.lang.perl:5219 comp.unix.sysv386:7831 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.jpl.nasa.gov (Larry Wall) Newsgroups: comp.lang.perl,comp.unix.sysv386 Subject: Re: Perl unpack/tacct file Keywords: pack, unpack, tacct files Message-ID: <1991May6.225335.11550@jpl-devvax.jpl.nasa.gov> Date: 6 May 91 22:53:35 GMT References: <1991May04.185409.24228@pinhead.pegasus.com> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 52 In article <1991May04.185409.24228@pinhead.pegasus.com> todd@pinhead.pegasus.com (Todd Ogasawara) writes: : : I just started using Perl a few weeks ago and have run into a problem when : trying to use unpack to look at 'tacct' type accounting files on an 386 box : running Interactive UNIX 2.2 (UNIX System V/386 R3). I'm pretty sure I : understand the structure of this file type since C programs I've written to : read it work fine. The C structure of this file looks like this: : : #p = prime time, np = non-prime time : #struct tacct { : # unsigned short ta_uid; /* userid */ : # char ta_name[8]; /* login name */ : # float ta_cpu[2]; /* cum cpu time, p/np (mins) */ : # float ta_kcore[2]; /* cum kcore-minutes, p/np */ : # float ta_con[2]; /* cum connect time p/np, mins */ : # float ta_du; /* cum disk usage */ : # long ta_pc; /* count of processes */ : # unsigned short ta_sc; /* count of login sessions */ : # unsigned short ta_dc; /* count of disk samples */ : # unsigned short ta_fee; /* fee for special services */ : #}; : : Here's the perl program I've tried to use to read a tacct file with. (BTW, : I'm using Perl 4.0 patch level 3). : : open(TACCT,"/usr/adm/acct/sum/tacct"); : : while(read(TACCT,$tacct,52)) { : ($uid,$name,$cpuP,$cpuNP,$kcoreP,$kcoreNP,$conP,$conNP, : $du,$pc,$sc,$dc,$fee) = : unpack("S A8 f f f f f f f l S S S",$tacct); : local($TCONNECT) = $conP + $conNP; : printf "%4d %8s %7.2f %d %d\n", : $uid, $name, $TCONNECT, $sc, $dc; : } : : The $uid and $name variables contain what I expect it to. However, : everything else that follows seems to be one off. I.e., The $dc variable : should contain the number of disk samples but seems to contain the number : of login sessions instead. The floating point values are all over the : place. I know that I must be reading in the floating point variables : incorrectly, but I don't know what it is that I'm doing wrong. BTW, I have : the Wall & Schwartz "Programming Perl" book and have gone through the : sections describing pack and unpack several times to try to understand what : is going on here. Your C compiler is probably throwing you a curve by aligning the first float to a 4-byte boundary. Try saying unpack("S A8 x2 f f f f f f f l S S S",$tacct); Larry