Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 3 Jun 1998 09:17:04 -0400 (EDT)
From:      CyberPeasant <djv@bedford.net>
To:        wheely@thevortex.com (wheely)
Cc:        freebsd-questions@FreeBSD.ORG
Subject:   Re: Terminate signal
Message-ID:  <199806031317.JAA05978@lucy.bedford.net>
In-Reply-To: <199806030811.UAA19965@teresa.strip.net.nz> from wheely at "Jun 3, 98 08:17:52 pm"

next in thread | previous in thread | raw e-mail | index | archive | help
wheely wrote:
> When I "halt" the system naturally it sends the terminate signal to all
> processes. My users and I run a program that writes several files when it
> receives the terminate signal before terminating. My problem is that
> because I have such a slow IDE disk and several instances of the program
> are running, the time inbetween the signal and the actual termination is
> not enough for the writing process to finish.
> 
> The writing process consists of writing 3 files per program under temporary
> filenames (so if the quota is full it does not erase the current file) then
> moving it to its final name. Sometimes the files write ok and the moving
> does not occur, sometimes an empty file is written.
> 
> I do not have a problem with the program on a system with a desent SCSI disk.

 :-)

> My question is, is there a setting where I can increase the length of time
> between the terminate signal and the termination? If not has anyone got any
> ideas on workarounds? I'm using 2.2.5-RELEASE currently.

MAYBE-FIX:

If SIGTERM is already doing what you want, you could deliver
a SIGTERM with killall before shutdown.  Man killall.
Shutdown then becomes: (This could be a script -- NOT setuid root).

	#! /bin/sh
	YAWN=5 
	/usr/bin/killall -TERM name-of-the-program
	/bin/sleep $YAWN
	/sbin/shutdown -h ....

killall seems to require the procfs file system to be mounted.

WORKAROUND:

	Don't run shutdown -h or shutdown -r.  Instead, run shutdown
without a -[flag], i.e. "shutdown now some.message.to.users"
This will take the system to single user mode; I believe init will
give your jobs a long time to exit. (long = 30 secs or more. Check the
init manpage). Once they're gone, run shutdown -h or -r, or just
run halt or reboot.

HACKAROUND:

	The workaround requires human presence at the console. 
For remote or automatic shutdown, you'll need (I think) to patch
the code for reboot/halt; the delays are hard-coded in. The relevant
part (I think) is around line 160 in /usr/src/sbin/reboot.c  There
are two sleep() calls, I would advise increasing the first from 2 to
whatever you please.  If you need more instruction on this, let
me know off-list. Although I am certain that this change will increase
the delay between the SIGTERM and the SIGKILL, I am not sure how it
will interact with unmounting filesystems, and so on. I am 99% sure
that it /won't make things worse/.

If the files are on an NFS mounted file system, you'll probably need
some special hacks.

Dave
--
	DISCLAIMER: If it can be disclaimed, it is.  
	DISCLAIMER: In particular, I don't represent any organization.

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199806031317.JAA05978>