Flushing - please help!
Dean R. Loew
loew at motcid.UUCP
Fri Nov 16 02:20:29 AEST 1990
I've never used this group before, and I really
hope someone can help.
I have a ksh script that contains the following
code:
(a.out >output >2 errors)&
job_number=`ps -r | grep "a.out" | sort -nr | \
head -1 | cut -c 2-5`
sleep <some time value>
kill -9 $jobnumber
The first line starts a C program, a.out, redirects
it and puts it in the background. This C program
executes an endless loop, and never dies. The second line
captures the job number of the C program. The third
line gives the C program plenty of time to print
some output, and the fourth line kills it.
The problem: The two files, `output` and `errors`
are empty after the kill command, even though the
a.out uses 'printf' to print a lot of stuff
to stdout. I imagine this is because 'printf'
uses buffered output.
THE QUESTION: Is there any way for my ksh script to
force the 'a.out' process to flush its buffers before
it kills it?
Another small question: Is there an easier way to capture the job
number above, instead of all of the hoopla I go through
with the greps and cuts. The sort and head commands
assure that I get this particular 'a.out', in case there are some
others running.
Any help would be GREAT! Thanx in advance.
Could you please post any help to this newsgroup,
as the address listed below may not work.
Dean Loew loew at motcid.uunet.uu.net 1-708-632-6774
Motorola of Arlington Heights
More information about the Comp.unix.questions
mailing list