Visit Our UNIX and Linux User Community


Stopping A process


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Stopping A process
# 1  
Old 12-05-2007
Stopping A process

Hi

I want to stop a process using a shell script. how do i do that?

ie, to simulate ps -ef|grep Process name
get the process id and kill -9 process id

plz help...
# 2  
Old 12-05-2007
How are you going to identify the process to kill?
# 3  
Old 12-05-2007
Quote:
Originally Posted by porter
How are you going to identify the process to kill?
it will be input to the script
# 4  
Old 12-05-2007
Killing a process based on the process name can be tricky.
The process name might be a substring of another process.
And it could exist more than once.

This should work:

PID=`ps -ef | grep -w ${PROCNAME} | awk '{print $2}'`
kill -9 $PID

This will kill all occurences of the PROCNAME.

I have come across the fact that the process name you want to kill is actually a process with some arguments, like "httpd -f".
In this case it can't hurt to use quotes:

PID=`ps -ef | grep -w "${PROCNAME}" | awk '{print $2}'`
kill -9 $PID

Would you like to only kill the last occurence of the PROCNAME you may use:

PID=`ps -ef | grep -w "${PROCNAME}" | awk 'END {print $2}'`
kill -9 $PID

Perhaps others have better suggestions as I am still learning too :-)
# 5  
Old 12-05-2007
it is not wiser to kill the process by -9 option

please read the following the article, which might help you out
When should I use kill -9?

Previous Thread | Next Thread
Test Your Knowledge in Computers #589
Difficulty: Medium
A binary search algorithm requires that the array being searched is sorted in descending order.
True or False?

9 More Discussions You Might Find Interesting

1. Red Hat

stopping you have mail.....

Hi, on server Red Hat Enterprise Linux AS release 3, I am getting the mail "you have mail" can any body suggest how to stop this? mail are getting generated in below path. /var/spool/postfix/maildrop, due to which heavy file are getting generated. though sendmail service is stopped. ... (0 Replies)
Discussion started by: manoj.solaris
0 Replies

2. Shell Programming and Scripting

stopping process started with "while"

Hello unix forum ! how do i get rid of this while thing ? if started some where by crontab for example. while ; do ./script > /dev/null ; done & or for example if in terminal while ; do ./script ; done & and the script is outputing and I can't write commands. other... (2 Replies)
Discussion started by: max_475
2 Replies

3. UNIX Desktop Questions & Answers

stopping running process

hi all, I am using red hat AS 4 linux enterprise,i need to run my application such that while its running no other process shuld run all the remaining process should be suspended ,i need to use whole of the process only for that application to run ,can anyone suggest me how to do this. ... (3 Replies)
Discussion started by: srilakshmi
3 Replies

4. Shell Programming and Scripting

Stopping a command in between

Hi Is it possible to stop a command executing after certain time? I have this command say prstat which keeps on giving the values etc of the processes after every 1 sec(refreshes the screen) What I want is just stop the execution after first screen Since I have written this command in shell... (3 Replies)
Discussion started by: superprg
3 Replies

5. UNIX for Advanced & Expert Users

stopping a processor

hi, Can any plz tell what is the command for stopping a processor? suppose a system is accessing 10 processors and we want to stop the 3rd & 6th processor then whats the command in Unix? thank u (2 Replies)
Discussion started by: nm_virtual
2 Replies

6. Shell Programming and Scripting

I can't resume a process after stopping it!

Hello, I have a process running, for example a "top". I send it a signal to stop it kill -s SIGSTOP 3423 It works, but when I want to resume it by kill -s SIGCONT 3423 It does not work. Help me please..... I have Fedora Core 4. Thank you (0 Replies)
Discussion started by: Nene
0 Replies

7. Shell Programming and Scripting

stopping a script

i want to stop a script from running after one minute, using the sleep command, and then kill the process. anyhelp with this. (2 Replies)
Discussion started by: AtomJ22
2 Replies

8. AIX

Stopping multiple process on AIX

I'm trying to update a shared library (*.so) in our AIX machine. However, when I tried to delete the old *.so file, I get this error -> Cannot open or remove a file containing a running program. Based on the information I gather from the net, shared libraries are not unloaded (the file remains... (3 Replies)
Discussion started by: soulfactory2002
3 Replies

9. UNIX for Advanced & Expert Users

Stopping a print request

Im running a solaris 9 system and keep getting this message: Request to LXKF894CB (unknown printer) from zion. This happen because there was a mis configured printer and a job was submitted to it. I fix the printer issue but this message keeps repeating and the PID keeps going up. How can i... (5 Replies)
Discussion started by: meyersp
5 Replies

Featured Tech Videos