csh - how to automatically kill background processes on logout

Chris Torek chris at mimsy.UUCP
Sun Aug 6 05:24:03 AEST 1989


In article <72 at harald.UUCP> jba at harald.ruc.dk (Jan B. Andersen) writes:
>In Bourne shell background processes started with '&' will automatically
>get killed on logout (hangup). But the man page for csh says: "Processes
>running in the background (by &) are immune to to signals... including
>hangups."
>
>How do I enable SIGHUP? In .logout? Should I kill them instead?

Right:

	% cat .logout
	tf=/tmp/k$$
	jobs >$tf
	if (! -z $tf) then	# there are jobs
		jobs >$tf.1	# rerun it to dump `Done' jobs
		grep -v Stopped <$tf.1 >$tf; rm $tf.1
				# cannot use a pipe here
		if (! -z $tf) then	# there are running jobs
			eval `echo kill -1; sed 's/.\([0-9]*\).*/%\1/' <$tf`
		endif
	endif
	rm $tf

Warning: I have not tested this and it may run afoul of various
csh quirks.  The important trick is to run `jobs >file', not
`jobs | command', as the latter runs `jobs' in a subshell and
thus produces no output (although `jobs | <any-csh-builtin>' is
good for a laugh :-) ).
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.unix.questions mailing list