This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Buffered output/Forked processes


  Sorry, I should have stated my question better -- look at the following command on cygwin:

  % vmstat 1 > somefile.txt &
  (...time passes...)
  % ls -la somefile.txt
  -rw-r--r--    1 leitaon  mkgroup-      0 Oct 13 13:48 somefile.txt
  (...time passes...)
  % ls -la somefile.txt
  -rw-r--r--    1 leitaon  mkgroup-     4096 Oct 13 13:52 somefile.txt
  
  What is going on is that vmstat/cygwin/glibc/whatever is just buffering the output until the buffer is full (4096 bytes) at which point it flushes it. The effect I want is for each line outputed from vmstat to go straight into the file (or in my original example, into the pipe and the Perl script) -- the problem is *not* on the Perl script but the way vmstat is buffering the output.

  Any clues ?

  Thanks.

--Nuno.


-----Original Message-----
From: Reini Urban [mailto:rurban@x-ray.at]
Sent: 13 October 2004 13:12
To: Nuno Leitao
Cc: 'cygwin@cygwin.com'
Subject: Re: Buffered output/Forked processes


Nuno Leitao schrieb:
>   I have a Perl script which looks like:
> 
>   open( VMSTAT, "vmstat 5|" );
>   VMSTAT->autoflush( 1 );
>   while( <VMSTAT>) {
>      print $_;
>   }
> 
>   Now, under Linux and other UNIX OS's this works fine, and "print $_" will
> print the vmstat output every 5 seconds since the output from vmstat is not
> buffered. Under Cygwin however, it seems vmstat will always buffer its
> stdout with the undesirable effect that lines come in batches as the output
> buffer gets full and is flushed by the Cygwin C libraries.
> 
>   Is there a way to go around this without having to patch and recompile
> vmstat or other binaries I might want to use in this way ?

basic perl question, not cygwin related.
$ perldoc -q buffer
$ perldoc -f select

cygwin perl doesn't honor $| ? not true.
Because you told VMSTAT not to buffer.
But you shold have told it to STDOUT.

open( VMSTAT, "vmstat 5|" );
VMSTAT->autoflush( 1 );
$| = 1; # STDOUT is selected so STDOUT will get unbuffered.
while( <VMSTAT>) {
     print $_;
}


-- 
Reini Urban
http://xarch.tu-graz.ac.at/home/rurban/


Please note that:
 
1. This e-mail may constitute privileged information. If you are not the intended recipient, you have received this confidential email and any attachments transmitted with it in error and you must not disclose, copy, circulate or in any other way use or rely on this information.
2. E-mails to and from the company are monitored for operational reasons and in accordance with lawful business practices.
3. The contents of this email are those of the individual and do not necessarily represent the views of the company.
4. The company does not conclude contracts by email and all negotiations are subject to contract.
5. The company accepts no responsibility once an e-mail and any attachments is sent.

http://www.integralis.com


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]