need to kill a number of processes with name "XYZ" at a time using shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need to kill a number of processes with name "XYZ" at a time using shell script
# 1  
Old 04-08-2011
MySQL need to kill a number of processes with name "XYZ" at a time using shell script

Hi,

when i grep for the process "XYZ" , there will be some good number of processes with that name, i want to kill all the these processes at a time using shell script?

Any help needed for this action.

Thanks

Regards,
Anil
# 2  
Old 04-08-2011
killall -r ?
# 3  
Old 04-08-2011
Code:
ps -ef |grep "XYZ"|xargs kill

# 4  
Old 04-08-2011
/usr/bin/kill[8]: root: Arguments must be %job or process ids
getting the above error with command ps -ef |grep "XYZ"|xargs kill
# 5  
Old 04-08-2011
Quote:
Originally Posted by anilmanepu
/usr/bin/kill[8]: root: Arguments must be %job or process ids
getting the above error with command ps -ef |grep "XYZ"|xargs kill
Code:
ps -ef | awk '/XYZ/{print $2}' | xargs kill

# 6  
Old 04-08-2011
Command for your shell script

killall -e should do it for you without having to invoke grep if you already know the process name.

It also has regular expression support via the -r switch so you should be able to take your grep expression and place it there if you still need to do a regex.

For more information see the link below. Smilie
I can't post links yet because I don't have 5 posts, here's an exploded version of the link

linux dot die dot net forwardslash man forwardslash 1 forwardslash killall

[edit] Didn't see the killall -r up a couple posts, leaving here since it has the link for more info

Last edited by jtollefson; 04-08-2011 at 11:26 AM.. Reason: add more text
# 7  
Old 04-08-2011
Quote:
Originally Posted by jtollefson
killall -e should do it for you without having to invoke grep if you already know the process name.
WARNING, WARNING.

If you try killall on a non-Linux system you might be very surprised Smilie It often has a more, well, literal meaning.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Root running a script calling to scp using user "xyz" is not authenticating!

Close duplicate thread. (0 Replies)
Discussion started by: denissi
0 Replies

3. Shell Programming and Scripting

What is the use of "finger" command & how to use it to kill the online processes ?

Hi there, I am eager to know what exactly is the use of "finger" command & how to use it to kill the online processes ? :b: (1 Reply)
Discussion started by: abhijitpaul0212
1 Replies

4. Shell Programming and Scripting

"ksh: XYZ: parameter not set" in .profile

Hi, A very basic query. I am working on two different UNIX servers and I see different behaviours for my user id. This has to be a setting in the .profile, but I can't seem to find where :confused: So, in one server if I type echo $XYZDD (a random variable), I get a blank line with no... (2 Replies)
Discussion started by: ALDonP
2 Replies

5. Shell Programming and Scripting

Automation of "Kill script by name"

The following "NAME" is the keyword to use to kill all processes containing it. While the command is very useful, it is user-unfriendly to type it in terminal. I've tried alias and make it a shell script but as NAME is inside awk so the problem becomes complicated. Could anybody advise? ps -ef |... (13 Replies)
Discussion started by: watashi
13 Replies

6. UNIX for Dummies Questions & Answers

Kill child processes, when parent is "bash"

Consider this simple command line bash -c 'echo $$ ; sleep 10000'This will print the newly created bash PID and sleep for a long time. If I go to another terminal and do something like ps -flax | grep leepI'll see something like 501 92418 91910 0 0:00.00 ttys000 0:00.00 bash -c echo $$... (5 Replies)
Discussion started by: teras
5 Replies

7. Shell Programming and Scripting

Shell Script to identify the line number containing a particular "string"

Hi, I have a log file, where i am required to identify the line number, where a particular string/line appears in the log file. And then copy 200 lines above that line number to a new file. Can someone provide pointers on how to write this script or what command to be used ? Any... (2 Replies)
Discussion started by: kk2202
2 Replies

8. AIX

"too big" and "not enough memory" errors in shell script

Hi, This is odd, however here goes. There are several shell scripts that run in our production environment AIX 595 LPAR m/c, which has sufficient memory 14GB (physical memory) and horsepower 5CPUs. However from time to time we get the following errors in these shell scripts. The time when these... (11 Replies)
Discussion started by: jerardfjay
11 Replies

9. Shell Programming and Scripting

How to remove "New line characters" and "spaces" at a time

Dear friends, following is the output of a script from which I want to remove spaces and new-line characters. Example:- Line1 abcdefghijklmnopqrstuvwxyz Line2 mnopqrstuvwxyzabcdefghijkl Line3 opqrstuvwxyzabcdefdefg Here in above example, at every starting line there is a “tab” &... (4 Replies)
Discussion started by: anushree.a
4 Replies

10. UNIX for Advanced & Expert Users

"kill -14 pid" doesn't works on all processes !!

If I try to run "kill -14 pid", some processes in my application get terminated , while some keeps running. If SIGALRM signal is sent, they should make an exit. What's the reason any process keeps on running. (1 Reply)
Discussion started by: poojac
1 Replies
Login or Register to Ask a Question