Killing the correct process

Maarten Litmaath maart at cs.vu.nl
Fri Mar 2 11:00:44 AEST 1990


In article <1813 at root44.co.uk>,
	gwc at root.co.uk (Geoff Clare) writes:
)...
)Glad to hear you've seen the light (at last :-).

My original script explored the (portable/V7) sh boundaries.
I wanted to distinguish between someone *else* killing the job and *timeout*
killing it; this was the purpose of the `-v' option (I know, there's a race
condition); as `timeout -v' already told me the job had timed out, I didn't
want the shell's `Killed' message; therefore I diddled with file descriptor
2; as I wanted a synchronous message I had to invoke an `sh -c' to do the
real work; to kill a leftover sleep I had to use the backquote construct.

)Your new script is the same as mine with one worthwhile addition and a
)few rather less useful (IMHO) ones.  Thanks for saving me the effort of
)implementing my suggested method for tidying up the leftover sleep.

There's still a better way, something like:

	for t in $timeout $delay
	do
		while test $t -gt $interval
		do
			sleep $interval
			kill -0 $$ || exit
			t=`expr $t - $interval`
		done
		sleep $t
		kill $SIG $$ && kill -0 $$ || exit
		SIG=-KILL
	done

)...
)SIGHUP:  you might want to do a "nohup timeout somecommand ... &"
              ^^^^^
	      Indeed.

)SIGALRM: is not for "timing out" a process, it's for use by a process, e.g.
)	 for timing out a system call or for sleeping.  If the process is
)	 using SIGALRM, all your "time out" will do is wake it up early.

In general you're right; however, is it inconceivable that the process has
been especially configured to cleanup on reception of a SIGALRM?

)SIGXCPU: is for limiting resource usage, and in any case is non-standard.

So what?  From `man init' on SunOS 4.0.3c:

	init catches the hangup signal (SIGHUP) and interprets it to
	mean  that  the  file /etc/ttytab should be read again.

"Boo hiss!  SIGHUP is for signaling a hangup on a terminal line!"

)The phrase "time out" when applied to a process really means "terminate
)before normal completion".  When you want to *TERM*inate a process you use
)SIG*TERM*.  Need I say more?

	"No.  You need to say less."
	-- Richard Sexton, richard at gryphon.COM

Couldn't resist! :-)
The phrase "time out" when applied to a process really means "kill
before normal completion".  When you want to *KILL* a process you use
SIG*KILL*.  Sic!
--
  "Belfast: a sentimental journey to the Dark Ages - Crusades & Witchburning
  - Europe's Lebanon - Book Now!" | maart at cs.vu.nl,  uunet!mcsun!botter!maart



More information about the Comp.unix.questions mailing list