APLawrence - Information and Resources for Unix and Linux Systems, Bloggers and the self-employed
RSS Feeds Get APLawrence.com by RSS











(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Home > News Posts > output buffer flush ––>Re: Please help on 'killprocess'...
Printer Friendly Version




News Group Posts

output buffer flush




From: Barry Margolin <barmar@genuity.net>
Subject: Re: Please help on "kill process"...
References: <268283d.0205171252.7ef8e547@posting.google.com>
<3CE5738F.20807@aplawrence.com> Date: Fri, 17 May 2002 22:10:42 GMT In article <3CE5738F.20807@aplawrence.com>, Tony Lawrence <tony@aplawrence.com> wrote: >rak wrote: >> The process I want to stop is a test program, it will keep running for >> 5 hours and I redirect the output to a data file. The problem is, the >> program can only be stopped by press "F3" key. If I use kill to stop >> it, the last few line of data will not be able to save to my data >> file. and if I manually run it and press F3 to stop it, the data file >> is OK. or if I don't redirect the output in the scripts, the full >> output from the program will shown on screen, even I use kill to stop >> it. So, how could I use scripts and save all the output into data >> file? ... >When you use kill -9, your program has no chance whatsover to clean >itself up. If it is well written, it should flush and close its files >on a kill -15 or kill -1. At least it has the opportunity to do so with >those signals; with -9 it has no choice. Most programs don't contain any special handling of those signals, so it probably won't help to change the signal. It's still a good idea, though; kill -9 should only be used as a last resort for a process that won't die any other way.












The reason this is happening is most likely that the program uses stdio.
When its output is not to a terminal, it's fully buffered, and when the
process is killed it doesn't flush its buffers.  If you can modify the
program, you should have it use setbuf() to turn off buffering of output.
If not, you can use Expect to have its output go through a pseudo-tty, so
that the output will be flushed automatically after every line (Expect
comes with a pre-written script that does this).

-- 
Barry Margolin, barmar@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
 

If this page was useful to you, please click to help others find it:  

Your +1's can help friends, contacts, and others on the web find the best stuff when they search.

Comments?



Click here to add your comments



Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar



Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.

g_face.jpg

This post tagged:

       - SCO_OSR5




Unix/Linux Consultants

Skills Tests

Guest Post Here