shell script to kill process with respect to terminal

Hi,

I've a script which kills all process, but i need a script shell script(sh), where it'll kill process on that particular terminal. below is example

TY=`tty`

for P in $TY 
        do
        `kill -9 $P 2>/dev/null`;
        done
        echo "test process killed"
        break
        fi
done

when i run this, i'm getting ERROR: TTY not found. this is an shell script which is running in background, and perl is calling this shell script.
say i want to kill process name sh, of that particular terminal. how to do this.

regards,
asak

What system are you on?
ps(1) is most likely the tool you could use to accomplish this.

On my system (bash on linux)

ps a

returns processes and associated terminals (TTY, second column)

From the output of 'ps' you can pull just the processes tied to particular tty.

If you have it: pkill -t tty

Regards,
Alister

1 Like

Thanks alister,

all process with respect to particular terminal go killed...

Thanks once again.

Regads
asak