shell script to kill process with respect to terminal


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell script to kill process with respect to terminal
# 1  
Old 06-21-2011
CPU & Memory 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
Code:
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

Last edited by Franklin52; 06-21-2011 at 11:09 AM.. Reason: Please use code tags, thank you
# 2  
Old 06-21-2011
What system are you on?
ps(1) is most likely the tool you could use to accomplish this.

On my system (bash on linux)
Code:
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.
# 3  
Old 06-21-2011
If you have it: pkill -t tty

Regards,
Alister
This User Gave Thanks to alister For This Post:
# 4  
Old 06-22-2011
Thanks alister,

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

Thanks once again.

Regads
asak
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to report file size, pid and also kill the process

Hi All, Looking for a quick LINUX shell script which can continuously monitors the flle size, report the process which is creating a file greater than certain limit and also kill that process. Can someone please help me on this? (4 Replies)
Discussion started by: vasavimacherla
4 Replies

2. Shell Programming and Scripting

Kill specific terminal using shell/bash

Hello elite shell/bash specialists, I have done plenty of STFW and some RTFM, but I cannot find a clear solution to my challenge Goal: My goal is to have a script(of any language, preferably shell/bash/anything that can run things on unix), which will kill specific unix terminal windows for... (0 Replies)
Discussion started by: kamil-mech
0 Replies

3. Shell Programming and Scripting

shell script to find a process by name and kill it

hi, Am a newbie to unix and wasnt able to write script to my requirement. I need a shell script, which should find a process by name and kill it. For eg: let the process name be "abc". I have different processes running by this name(abc), so should kill them all. Condition would be: if... (7 Replies)
Discussion started by: fop4658
7 Replies

4. Shell Programming and Scripting

Cron job and shell script to kill a process if memory gets to high

Hello, I'd like to set a cron job that runs a shell script every 30 minutes or so to restart a java based service if the memory gets above 80%. Any advice on how to do this? Thanks in advance! - Ryan (19 Replies)
Discussion started by: prometheon123
19 Replies

5. UNIX for Dummies Questions & Answers

Kill Duplicated Process by shell in crontab

Hi! I need your help, please. I'm in AIX node and sometimes listener process from an oracle instance gets duplicated, i mean that it get spawned a second listener process. As we can't apply changes to the databases on this months, i want to build a shell that can identify the second... (6 Replies)
Discussion started by: Pactows
6 Replies

6. Shell Programming and Scripting

Funny : why can't I kill my parent terminal in a script ?

Hellooooooo ;) Today I've created a script that does some things (not important). And for fun I want that it kills the terminal from which I launch it. (too lazy to press Alt-F4 lol) So I write #!/bin/bash kill $PPID but it doesn't work ... while if in my xterm I launch another xterm... (8 Replies)
Discussion started by: xib.be
8 Replies

7. UNIX for Dummies Questions & Answers

Script to start background process and then kill process

What I need to learn is how to use a script that launches background processes, and then kills those processes as needed. The script successfully launches the script. But how do I check to see if the job exists before I kill it? I know my problem is mostly failure to understand parameter... (4 Replies)
Discussion started by: holocene
4 Replies

8. Shell Programming and Scripting

Script to Kill a Process by Name...

Hello all... new to these forums and a bit of a newbie with linux aswell. I need to figure out how to write a shell script to kill a process by name as given to the script as an argument. I've got that part working OK, but i need to make sure that the script does not allow processes that are... (6 Replies)
Discussion started by: cannon1707
6 Replies

9. Shell Programming and Scripting

Kill a process from parent shell within a shell script

Hi, I am looking for a solution for the following problem: Im Using tcpdump within a shellskript started in a subshell by using brackets: ( /usr/sbin/tcpdump -i ... -c 1 ) - I want the outout of tcpdump saved in a variable - Than tcpdump-Process in the Subshell should be killed - and I... (6 Replies)
Discussion started by: 2retti
6 Replies

10. Shell Programming and Scripting

Shell Script to Kill Process(number of process) Unix/Solaris

Hi Experts, we do have a shell script for Unix Solaris, which will kill all the process manullay, it used to work in my previous env, but now it is throwing this error.. could some one please help me to resolve it This is how we execute the script (and this is the requirement) ... (2 Replies)
Discussion started by: jonnyvic
2 Replies
Login or Register to Ask a Question