Terminate process


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Terminate process
# 1  
Old 07-09-2005
Terminate process

We have a system user "oracle_usr" always run some process in the system , but sometimes , these processes will not stop automatically until we terminate the process , can suggest the method how to terminate the process that is run by "oracle_usr" and run over 10 minutes ? thx
# 2  
Old 07-09-2005
Quote:
Originally Posted by ust
We have a system user "oracle_usr" always run some process in the system , but sometimes , these processes will not stop automatically until we terminate the process , can suggest the method how to terminate the process that is run by "oracle_usr" and run over 10 minutes ? thx
if this really happens all the time, you should consider writing a script to automate this process for you. But if it does not happen all that often, you can use the following interactive procedure (which could also be a basis for a script).

In a shell, run ps --user=oracle_usr --format=pid,user,comm,etime --sort etime
This will return all of the active processes owned by oracle_usr, sorting them by how long they have been running for (in [[dd-]hh:]mm:ss format). This elapsed time will be the last column in the table returned to you. The first column with be the PID (process id) of each process. Record the PID's of the proccesses with elapsed times of over 10 minutes (or whatever time you want). Then using the PID of each process, you can send it a signal to terminate it properly. But you should read the Oracle documentation to understand what would be the most appropriate signal to use.
Speaking in generic terms, you can terminate a process by sending it a TERM or KILL signal. E.g., for each process that you want to kill, you could try kill -TERM <PID>, and if that does't work, kill -KILL <PID> . By the way, to use kill on a process, you have to own it (i.e., here be oracle_usr) or be a privelaged user.

Last edited by hadarot; 07-13-2005 at 12:16 AM..
# 3  
Old 07-09-2005
thx reply , but I have no experience to write a script to do that , could you provide some help . thx a lot
# 4  
Old 07-10-2005
Well if you are running Oracle on *nix, you probably should have someone around who knows shell scripting quite well, because an Oracle system is heavy and not so easy to maintain properly.
If you want to learn shell scripting, there are many books and tutorlals on the web. One book that is highly regarded by many is UNIX Shell Programming, by Stephen Kochan.

Last edited by hadarot; 07-31-2005 at 10:18 PM..
# 5  
Old 07-11-2005
here is your script

Here is the script you asked for. I presume that only one program hangs; thus you don't want to kill all processes owned by oracle_usr, but only those that are the program that hangs. You have to figure out what program that is. (You can use ps -U oracle_usr to list the user's processes.)
Copy and past the script below into an editor, and you can change $2 to the name of the command that hangs (you don't need ot include the argument, if any, but just the command itself). You should also change $1 to "oracle_usr", and change the signal as apropriate (READ THE ORACLE DOCS!!).
(The script as it is now lets the user specifiy the user and the command to kill when invoking the script. But if it is alsways oracle_usr and the program that hangs, this is not necessary; just specify these by editing the script as I just told you).
When you are done editing the script, save it as a file, and make it executable with chmod +x <FILENAME>. Then you can invoke it from the command line as root or as oracle_usr.

Code:
#!/bin/sh

## script to kill each process of a particular command name
## of a particular user, if that process is over 10 minutes old

## in this line, please replace "$1" with "oracle_user"
user="$1"

## please replace "$2" with name of program that you want to kill
command="$2"   

## please read Oracle documentation to ascertain which signal
## is appropriate to terminate this process. Then you can replace TERM
## here with the appropriate signal if necessary
signal=TERM

# get PID's of processes to kill, then kill them with specified signal
ps -U "$user" -o comm,etime,pid | awk -v com="$command" '$1 == com && $2 ~ /:[0-9][0-9]:[0-9][0-9]|[1-9][0-9]:[0-9][0-9]/ { print $3 }' | while read pid
do
   echo killing process $pid ...
   kill -$signal $pid
done


Last edited by hadarot; 08-02-2005 at 11:44 PM..
# 6  
Old 07-12-2005
I think you had better get a better understanding of scripting and especially ORACLE itself before you progress much further.

I am not convinced that you should go around simply killing ORACLE processes. You may be doing some harm to your installation or data by doing so, because the kill may not be allowing the process to terminate (tidy up) properly.

Just a cautionary note!

MBB
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Terminate a process using shell script

Hi, I am writing a shell script to run a process and write the output of the process to a file. Inside program.sh: ./process.sh > tempfile .. open tempfile do the following But the problem is that process.sh is running indefinitely and program.sh is not executed completely. Can... (4 Replies)
Discussion started by: dreamgirl314
4 Replies

2. Shell Programming and Scripting

Terminate initially if error found...

Hi, I have written a shell script which is a combination of 5 scripts into one. We have a Record Claim indicator in the scpt ($rc) with which we can come to an conclusion if the script failed to load the data or if the data loaded successfully. Can any one please help me as to how to... (16 Replies)
Discussion started by: msrahman
16 Replies

3. UNIX for Dummies Questions & Answers

Terminate a port connection

I have executed a command which has ports that have to be assigned. then I deleted the files. Now I need to reinstall the command. but it says the ports are not free How to terminate the port connections and reinstall in solaris unix ---------- Post updated at 09:07 PM ----------... (7 Replies)
Discussion started by: sriki32
7 Replies

4. Solaris

Application terminate

OS : Solaris X86 gcc version 3.4.6 when i run my application, C with Motif application crashed and formed core. I collected the truss ouput. Incurred fault #6, FLTBOUNDS %pc = 0xFE8B35CD siginfo: SIGSEGV SEGV_MAPERR addr=0x00000275 Received signal #11, SIGSEGV siginfo:... (2 Replies)
Discussion started by: satish@123
2 Replies

5. Programming

command to terminate

hi all how to terminate command eecution process. can you please show me the way thank you (2 Replies)
Discussion started by: munna_dude
2 Replies

6. UNIX for Advanced & Expert Users

Interrupt signal Control C takes too long to terminate a process

I have a process to terminate, and when keying Control C/ kill -int , it takes 15 minutes to half an hour to terminate the process. I've tried using kill -2, or keying control c twice, however the process seem to be killed abruptly, without writing into the log file. So the only way in order to... (8 Replies)
Discussion started by: paqui
8 Replies

7. Shell Programming and Scripting

terminate process

I want to have a script to terminate the system process that generated by user oracle_usr and have already processed for over 10 minutes , could suggest the script ? thx (1 Reply)
Discussion started by: ust
1 Replies

8. Shell Programming and Scripting

terminate the process

In my system , there are a system user "cronusr" , it is mainly to run the crontab job in the database .Sometimes the cronjob process will be failure ( due to some reason ) so that many cronusr process are in the system , it affect other process in the system , I want to have a script that can... (2 Replies)
Discussion started by: ust
2 Replies

9. Shell Programming and Scripting

Terminate session on completing script

Hai all.. How do i terminate my telnet session automatically when my java applicatiion exits. i have a file run which executes my java application and takes care of all class and library path settings prior to the execution. I would like to terminate my session when my application exits. The... (4 Replies)
Discussion started by: deepsteptom
4 Replies

10. Shell Programming and Scripting

How to terminate a tail -f

I am developing a script with a tail -f in it. My problem is how to terminate it and execute the next line. (4 Replies)
Discussion started by: DonVince
4 Replies
Login or Register to Ask a Question