fouts@ames-unixb.ARPA (08/14/84)
From: Martin Fouts <fouts@ames-unixb.ARPA> [] I now find myself with a system running 4.2bsd Unix on which I have operators who from time to time will have to kill off a process for a user. Usually the user will know their username and sometimes they will know their terminal id, but rarely will they know the actual process id to kill. Although I could train my operators to use ps to find the process number, I would rather use an approach in which the operator fed the username and tty id to a program which then listed the processes belonging to that user on that tty and asked which ones to kill. The question is: What is the cleanest way using C to determine which processes belong to (who owns whom here anyway?) a given tty? The routine has to work for 4.2, and it would be nice if it would also work for system 5. Please reply to me at fouts@ames-nas-gw and I will sumarize if there is enough interest. Thanks in advance Martin Fouts NASA Ames Research Center fouts@ames-nas-gw
gwyn@BRL-VLD.ARPA (08/14/84)
From: Doug Gwyn (VLD/VMB) <gwyn@BRL-VLD.ARPA> Let the users kill off their own bloody processes. UNIX is not supposed to require operators. I use the following scripts which are based on versions from Kernighan & Pike: #!/bin/sh # zap -- kill all processes matching pattern # adapted from Kernighan & Pike # last edit: 84/05/19 D A Gwyn # SCCS ID: @(#)zap.sh 1.1 PATH=/usr/5bin:/bin:/usr/bin HEAD=/vld/bin/head PICK=/vld/bin/pick IFS=' ' sig= case $1 in "") echo 'Usage: zap [-2] pattern' 1>&2; exit 1;; -*) sig=$1; shift;; esac ps -ag | $HEAD 1 if pdp11 then exec kill $sig `$PICK \`ps -ag | egrep "$*" | egrep -v 'zap|egrep'\` | awk '{print $2}'` else exec kill $sig `$PICK \`ps -ag | egrep "$*" | egrep -v 'zap|egrep'\` | awk '{print $1}'` fi #!/bin/sh # head -- print first few lines of file # last edit: 84/05/19 D A Gwyn # SCCS ID: @(#)head.sh 1.1 PATH=/usr/5bin:/bin:/usr/bin if [ $# -eq 0 ] then n=10 else case $1 in [0-9]*) n=$1; shift;; *) n=10;; esac fi exec sed -e ${n}q $* #!/bin/sh # pick -- select arguments # adapted from Kernighan & Pike; to be replaced some day by C version # last edit: 84/05/19 D A Gwyn # SCCS ID: @(#)pick.sh 1.1 PATH=/usr/5bin:/bin:/usr/bin for i do echo "$i? \c" > /dev/tty read response case $response in [yY]*) echo $i;; [qQ]*) break;; esac done < /dev/tty
fouts@orville-ec.ARPA (08/15/84)
From: Martin Fouts <fouts@orville-ec.ARPA> Doug Gwyn says: >Let the users kill off their own bloody processes. UNIX is not >supposed to require operators. It is true that many UNIX user's assume the philosopy that the machines are hands-on and without operators. However, this isn't always possible, and as UNIX becomes used on larger systems, more cases of situations requiring operator assistance will occure. Given that I will require my operators to perform functions like killing processes running on a given tty, I would like that function to be as easy and error free as possible. Let me reword the question: Within a running C program, I have available to me a username and tty for a process. What is the cleanest way to determine the process number? ----------
gwyn@BRL-VLD.ARPA (08/16/84)
From: Doug Gwyn (VLD/VMB) <gwyn@BRL-VLD.ARPA> The cleanest way is STILL to run "ps" (with appropriate options) and scan for the combination that you are interested in (e.g. matching UID & CTTY). That way, when the kernel data structures change (ours do every once in a while) your "killer program" will still work.
hjb%camsteve@UCL-CS.ARPA (08/17/84)
From: Harry Barman <hjb%camsteve@UCL-CS.ARPA> <I'm-not-sure-if-this-bug-really-exists-but-just-in-case> You might need someone else to kill off your process if you do something like this in your main csh on 4.2bsd... % set wombat = `leave 2100` the cshell will jam up until the leave process goes away!, and there seems to be no way you can kill it from that terminal, you either have to go log in and kill it from another terminal, or get your friendly super-user person to do the evil deed. If anyone knows of a way around this hanging up problem I'd be glad to hear of it. Harry J. Barman University of Cambridge Computer Lab., Cambridge, UK. P.S. Is there still a line eater out there, or is it just another sewer dweller.
norm@rand-unix.ARPA (08/20/84)
From: Norm Shapiro <norm@rand-unix.ARPA> Could you let me know what you find out about this? Thanks very much norm shapiro