Killing the correct process

Blair P. Houghton bph at buengc.BU.EDU
Sun Feb 25 10:41:28 AEST 1990


In article <5650 at star.cs.vu.nl> maart at cs.vu.nl (Maarten Litmaath) writes:
>In article <5410 at buengc.BU.EDU>,
>	bph at buengc.BU.EDU (Blair P. Houghton) writes:
>)...
>)Sending a kill -HUP to a login-shell in the console window
>)of a uVAX workstation Running Ultrix clobbers all of a
>)login's processes and cycles the X server.
>
>Ever heard of `signal(SIGHUP, SIG_IGN)'?

I use HUP because it gives the honest processes a chance to
use `signal(SIGHUP, somethinguseful)'.

If you want, you can try this:

	stream_type fp;
	char line[WAYBIG];

	/* Already got user's uid via whatever means. */
	fp = popen("/bin/ps axl","r");
	while ( fgets(line,sizeof(line),fp) != (char *)NULL )
	    if ( uid == parse_for_uid(line) )
		kill( parse_for_pid(line), SIGKILL );
	pclose(fp);

SIG_IGN that!

(BTW, most of the time in that loop is spent waiting for
the `ps axl' to get aroung to its first line of output,
so it's more economical than one would think, at first.)

Of course, this is overkill when the only people I plan to
force the schedule on are almost uniformly without any
knowledge of unix, much less esoterica like execl's.  I'll
know well anyone who knows what a SIG_IGN is, and I'll
trust them not to bust my stuff, or I won't let them log in
at all.

It's obvious that unless you're trying to implement it as a
convenience rather than a security measure you're going to
have to rewrite the kernel, or add a killsession() call,
or getcherself a Real Operating System (hah!)...

>Furthermore: race conditions!

Which never elaborate themselves...

>)It's still a crap-shoot, but it's a crap-shoot with
>)probability of failure that has an *upper* bound of
>)1/30,000.  That is one in 30,000 times when the same
>)person has logged out and logged back in on the same
>)workstation on the same day.  Such a situation is not
>)too common in a big lab with tons of students and lots
>)of workstations.  [...]
>
>I was talking of events with much higher probability.

Wot?  You can assign a PID to your own process?  I'd like
to see that...

				--Blair
				  "Blair -v"



More information about the Comp.unix.questions mailing list