kill the tty

Hello Experts
i'm having some trouble with a script.
the purpose is to kill all processes from a distinct tty in a HP-UX machine, given the User TTY.

it's to use like this:

killtty pts/tnb pts/tr pts/tD

here it is

#!/usr/bin/ksh
i=1
for i
do
[ ${i} ] || exit
kill -9 `ps -ft "${i}" | awk 'NR != 1 {print $2}'`
done

The problem is that it's leaving a zombie process, i don't know why.

i have adapted this script from one that Perderabo has indicated to me to kill all processes from a user given it's UserName.

Thanks for your help

A true zombie is not much of a problem. But look at the ppid field of the zombie. Do a ps "-fp n" where n is that ppid of the zombie. You will now be looking at the parent of the zombie. The zombie will persist until the parent issues a wait() system call. If the program is allowing zomblies to accumulate, it needs a fix. And you cam kill this parent process. That will reparent the zombie to init which will always wait for a dead child.

well , let's see
when i use this script, it kill's all the processes but one.
the user still appears when i use "who" and with "w" in the column "what" i have "-".using "who -u" it has a process number.
and when i try to make "ps -fu" on that number , nothing appears.
i'm a bit confused about this, so i'l try to understand this a litlle bit more. thanks Perderabo

ps -fp

sorry, i ment to write ps -fp
when i write "who -u" , this appears:

dist12 pts/tc Apr 8 17:03 0:35 8145 132.142.170.33

then i try to:

"ps -fp 8145", but nothing appears, just column headers.

even when i write "ps -u dist12", nothing appears.

When i write "w", it appears among all other users

User tty login@ idle JCPU PCPU What
dist12 pts/tc 5:03 37 -

there must be some script error ,like if the script was killing the processes in the wrong order.

Huh? What on earth does "who" have to do with anything? A zombie is a process that has terminated. You use "ps" to see processes. In "ps -el", the second field, labelled S (for state) will have a Z for any zombies. So "ps -el | grep Z" will give you a list of all of your zombies...if you actually have some.

well , i usualy use "who" to find who is logged.
when that line appears...

User tty login@ idle JCPU PCPU What
dist12 pts/tc 5:03 37 -

with that "-" in 7 column, the user isn't logged and i can't kill him any way, everything i try it's unusefull and the olny process number i can get is when i use "who -u". In this case it shows :

dist12 pts/tc Apr 8 17:03 6:42 8145 132.142.170.33

the number "8145" is the only PID that i find.

i don't know if this is a zombie, but i sure can't do anything with it.

as to knowledge about Unix or Scripting, don't be surprise about my ignorance. I only started while ago to learn.

and you have been most helpfull Perderabo
thanks for that

Well what's happening there is a daggling utmp entry. How that happened depends on exactly how you logged in. In a typical scenario, telnetd is forked when someone connects via telnet. telnetd forks a login program which makes the utmp entry that you saw. The login program execs a shell. Eventually the shell exits. telnetd is the parent of that shell and notices the death of its child. So it cleans up that utmp entry and exits.

Now, consider what would happen if that telnetd instance was killed with a -9 signal. It dies immediately. It can't clean anything up.

I see you are still going straight for the -9 in your script. You might want to try the advice I gave in that first thread.

With all of this said, the telnetd instance does not normally acquire the terminal as a controlling terminal and so I would not expect this particular script to kill telnetd. And you may not be using telnet anyway. Still, somehow, the parent process of the shell is dying permaturely. And I would tend to suspect your -9 habit as the cause.

Also the contents of the utmp file is not really important. People can connect and not have a utmp entry. And, as you see, utmp can have garbage laying around. ps is the command to use to know what's happening on your system.

thanks for that explanation
The users login using telnet
and i did follow your advise on using -15 instead of -9.
The problem is that when users login, the profile send's them directly to the aplication they use on the machine , and using -15 on that first script that you pointed to me, will kill the aplication processes but living them in the operating system, wich i don't want to happen. I believe this has to do with the profile, but i'll have to check that out. On this script i'm now using -15 and i will see how it goes.
thanks a lot Perderabo

with this script , -15 is working fine and no longer (at least till now) left me with that kind of processes.
So, you'r right
thanks once again