Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Please help on "kill process"...

13 views
Skip to first unread message

rak

unread,
May 17, 2002, 4:52:30 PM5/17/02
to
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?
Please help me sovle the problem.
Thanks!

the scripts:
testprocess >datafile 2>&1 &
sleep 50000
kill -9 `ps -e|grep testprocess |cut -b 1-6`

Tony Lawrence

unread,
May 17, 2002, 5:14:03 PM5/17/02
to


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.

Try it, you might get lucky.


--

Tony Lawrence
SCO/Linux Support Tips, How-To's, Tests and more: http://pcunix.com
Free Unix/Linux Consultants list: http://pcunix.com/consultants.html

Mingzhe Li

unread,
May 17, 2002, 6:08:08 PM5/17/02
to

On Fri, 17 May 2002, Tony Lawrence 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?
> > Please help me sovle the problem.
> > Thanks!
> >
> > the scripts:
> > testprocess >datafile 2>&1 &
> > sleep 50000
> > kill -9 `ps -e|grep testprocess |cut -b 1-6`
>
>
> 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.
>
> Try it, you might get lucky.
>

Thanks Tony,

I tried -15 and -1, the program can't be killed. :(
Is there anyway that send "F3" to the process to exit normally?

Rak

Barry Margolin

unread,
May 17, 2002, 6:10:42 PM5/17/02
to
In article <3CE5738...@pcunix.com>, Tony Lawrence <to...@pcunix.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, bar...@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.

Tintin

unread,
May 17, 2002, 8:17:33 PM5/17/02
to

"rak" <ming...@yahoo.com> wrote in message
news:268283d.02051...@posting.google.com...

Don't use 'kill -9'. That gives the process no chance to clean up in an
orderly manner.


William Park

unread,
May 18, 2002, 2:41:34 AM5/18/02
to

1. 5 hours = 18000 seconds.

2. Try -TERM (15), -INT (2), -QUIT (3), respectively.

--
William Park, Open Geometry Consulting, <openge...@yahoo.ca>
8-CPU Cluster, Hosting, NAS, Linux, LaTeX, python, vim, mutt, tin

Randal L. Schwartz

unread,
May 18, 2002, 11:55:15 AM5/18/02
to
>>>>> "rak" == rak <ming...@yahoo.com> writes:

rak> kill -9 `ps -e|grep testprocess |cut -b 1-6`

Please do not use "kill -9". Please.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<mer...@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

Kenny McCormack

unread,
May 18, 2002, 2:23:25 PM5/18/02
to
In article <86offd8...@blue.stonehenge.com>,

Randal L. Schwartz <mer...@stonehenge.com> wrote:
>>>>>> "rak" == rak <ming...@yahoo.com> writes:
>
>rak> kill -9 `ps -e|grep testprocess |cut -b 1-6`
>
>Please do not use "kill -9". Please.

It is good advice, certainly, but seems not to be relevant here.
As someone else pointed out, most apps, particularly badly written ones (as
this one appears to be), don't setup signal handlers anyway.

It sure seems to me that Expect is the ticket here.

Bruce Barnett

unread,
May 19, 2002, 7:18:45 PM5/19/02
to
gaz...@yin.interaccess.com (Kenny McCormack) writes:

> It is good advice, certainly, but seems not to be relevant here.
> As someone else pointed out, most apps, particularly badly written ones (as
> this one appears to be), don't setup signal handlers anyway.


If they don't set up signal handlers, then kill -15 works JUST AS WELL as well
as kill -9.

But if they DID, then kill -15 (or better yet - "kill -TERM" ) is MUCH
BETTER than kill -9. -15 won't corrupt files.

So Randall is right. The only time I use "kill -9" is a last resoirt -
when "kill -15" doesn't work. And I usually use -1 before -15.


--
Sending unsolicited commercial e-mail to this account incurs a fee of
$500 per message, and acknowledges the legality of this contract.

John Bennett

unread,
May 20, 2002, 1:51:58 PM5/20/02
to
Sending a key to a shell?
This is what I have done before, I do not know if it can fit
your issue, but here is my 2-cents:

{
sleep 50000
echo 'THE-f3-Key-Code'


} | testprocess >datafile 2>&1 &

If memory servers me well, the code for the key in question for the
TERM in question can be found in the termcap.

I did not test this, this is some old shell stored away
in a tar ball. Good luck...

jb!

0 new messages