Operating System - HP-UX
1834200 Members
3042 Online
110066 Solutions
New Discussion

Buffering in the UNIX shells.

 
Leslie Chaim
Regular Advisor

Buffering in the UNIX shells.

Hello,

In my case its KSH.

Does anyone know if it's possible to turn off buffering in the KSH? I am running a batch process in the background that writes to a file, I would like to monitor this file with tail -f as the process runs.

Thanks
If life serves you lemons, make lemonade
10 REPLIES 10
Antoanetta Naghiu
Esteemed Contributor

Re: Buffering in the UNIX shells.

I am not sure I properly understand your question, but I guess you can try to use tee (see man tee), or to re-direct the output to a file... and use as you said tail -f.
Depends on type of apps as well.
Rick Garland
Honored Contributor

Re: Buffering in the UNIX shells.

Doing the tail -f command onto a file (a logfile) as the process runs does not require any tuning or buffer modifications.

If you have a process running in the background that is writing to a logfile, use tail -f on the logfile and the screen will scroll as activity is written to the logfile.
John Palmer
Honored Contributor

Re: Buffering in the UNIX shells.

How are you writing to the file? Are you doing shell print (or echo) commands?
James R. Ferguson
Acclaimed Contributor

Re: Buffering in the UNIX shells.

Leslie:

The man pages for tail provide a few interesting comments:

Under a discussion of the -f option..."tail enters an endless loop wherein it sleeps for one second then attempts to read and copy further records from the input file)."

This might suggest that you will not see characters until a newline character is passed (?).

Also: "Tails relative to end-of-file are stored in a 20-Kbyte buffer, and thus are limited in length. Therefore, be wary of the results when piping output from other commands into tail."

Hopefully this provides some insight (?).

...JRF...
Leslie Chaim
Regular Advisor

Re: Buffering in the UNIX shells.

Well here is some more clarification.

Thanks Antoinette you point out it depends on the apps used. Let me rephrase it:

Is it possible from KSH (or in UNIX) to have the effect of the C function call: setbuf(stdout, NULL)? Within the application itself, buffering is not disabled; I would like to disable it for monitory testing purposes without modifying my application.

Thanks,

Leslie
If life serves you lemons, make lemonade
Antoanetta Naghiu
Esteemed Contributor

Re: Buffering in the UNIX shells.

I am not aware about, but does C or other languages external intervention while running?
Did you try to use nobuffering in the application and eventually at compillation time use buffering, debug ...
Tracey
Trusted Contributor

Re: Buffering in the UNIX shells.

tail -f DOES wait until it receives a carriage return before it displays any new characters.
Leslie Chaim
Regular Advisor

Re: Buffering in the UNIX shells.

Yes I'm aware tail -f waits for the newline. That is OK.
On the other hand, if I do modify my application with a call to setbuf() I get the desired results, even with tail -f.

I would like to avoid the modification of the application by simply doing...
Well that's my question.

Thanks,

Leslie
If life serves you lemons, make lemonade
James R. Ferguson
Acclaimed Contributor

Re: Buffering in the UNIX shells.

Leslie:

I don't thing you can avoid the modification to your application. Seems like 'tail' is written to wait for the newline (as the man page material I high-lighted above states), and you're "stuck" with that as its implementation.

...JRF...
John Palmer
Honored Contributor

Re: Buffering in the UNIX shells.

I can't think of a way that the shell can influence your program other than providing something in the environment or a different argument. It would then be up to your program to make the required call to setbuf, there are no other means of overriding buffer behaviour that I am aware of.