Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83 (MC830713); site erix.UUCP
Path: utzoo!linus!decvax!mcvax!enea!erix!per
From: per@erix.UUCP (Per Hedeland)
Newsgroups: net.bugs.4bsd,net.unix-wizards
Subject: Possible 4.2 bug (process doing select() terminated by SIGTSTP)
Message-ID: <269@erix.UUCP>
Date: Mon, 20-Feb-84 04:01:26 EST
Article-I.D.: erix.269
Posted: Mon Feb 20 04:01:26 1984
Date-Received: Tue, 21-Feb-84 04:41:32 EST
Organization: L M Ericsson, Stockholm, Sweden
Lines: 59

<>
I posted this a couple of weeks ago, but I suspect it got lost somewhere,
since I got absolutely *no* response (*someone* must know!(?)):

Enclosed is a dummy program demonstrating the use of select() for catching
interrupts when expecting input. It works fine for this purpose, but strange
things happen if you try to suspend it: If you hit ^Z, the process just isn't
there anymore when you do a subsequent 'fg'. The (c)shell manages to exclaim
	[n]   Stopped      seltest
but that's all.

Closer examination reveals that the exit status says 'terminated by signal 18',
which is obviously true, but *why* is it terminated? Further clues:
The process doesn't actually terminate until the shell receives it's next
input, and if you send it a SIGCONT (from another terminal) before that, it
doesn't terminate at all.
If you select() for input from another terminal (than control) everything's
fine, but if you select() for input from control terminal and send SIGTSTP
from another, it still terminates.

I'm afraid I'm no expert on the interiors of the kernel, and although I've
vainly scanned through the code for select() (including the tty driver),
psig() etc leaves me far behind. Any info appreciated. (Please do *not* tell
me how to avoid the problem though, I'm interested in it's *cause*.)

Per Hedeland
{decvax, philabs}!mcvax!enea!per

seltest.c --------------------------------------------------------------------
#include 
#include 
#include 

interrupt(sig)
int sig;
{
	return;
}

main()
{
	int readfds;
	char line[80];

	signal(SIGINT, interrupt);
	while (1) {
		printf("question ? ");
		fflush(stdout);
		readfds = 1 << fileno(stdin);
		if (select(20, &readfds, (int *)0, (int *)0, (struct timeval *)0) > 0) {
			gets(line);
			printf("answer: %s\n", line);
		} else {
			printf("\nyou hit interrupt!\n");
		}
	}
}
------------------------------------------------------------------------------