Visit Our UNIX and Linux User Community

Killall script?

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Killall script?
# 1  
Old 05-02-2005
Killall script?

I am doing some system tuning and figuring out how to write a script that will kill multiple processes or all processes with the same owner. Can someone help me out? Thanks
# 2  
Old 05-02-2005
What shell are you using?

This is a simple enough script to write. See man ps for how to get the process ID. After that, simply loop through the process ID's and kill them ( man kill )assuming you are root (you are not going to be able to kill them otherwise).
# 3  
Old 05-02-2005
hmm yea i understand how to get the PIDs and use the kill command, but im not quite sure how to incorporate this into a script
# 4  
Old 05-02-2005
Not anywhere near a terminal so this is not at all tested. Also, cant remember off hand which field the PID is so you need to adjust the awk statement accordingly. Run the shell by passing in the user id of the user.


PROCESS_ID=`ps -e | grep ${USER} | awk -F" " '{print $1}'  2> /dev/null`

  kill -9 $ID
  if [ $? -ne 0 ]
     echo "Failed to Kill Process with PID = [ $ID ]"

# 5  
Old 05-02-2005
you could also try from the command line ...
kill -9 `ps -ef | awk '/$user/ && !/awk/ {print $2}'`

# 6  
Old 05-02-2005
Originally Posted by Just Ice
you could also try from the command line ...
kill -9 `ps -ef | awk '/$user/ && !/awk/ {print $2}'`


kill -9 `ps -fu $USER | awk '{print $2}'`

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "" script and a "" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

2. Shell Programming and Scripting

Shell script works fine as a standalone script but not as part of a bigger script

Hello all, I am facing a weird issue while executing a code below - #!/bin/bash cd /wload/baot/home/baotasa0/sandboxes_finance/ext_ukba_bde/pset sh UKBA 28082015 3 if then echo "Param file conversion for all the areas are completed, please check in your home directory"... (2 Replies)
Discussion started by: ektubbe
2 Replies

3. Fedora

Understanding Killall command , wait option

:wall:killall -wHi i need to understand how the -w option works in terms of processes. If this command is issued does it literally terminate all running processes ..wait for them all to be terminated and then return to standard output ? Thanks in advance (2 Replies)
Discussion started by: MrRobot
2 Replies

4. UNIX for Dummies Questions & Answers

Calling a script from master script to get value from called script

I am trying to call a script( from a master script( to get string type value from calling script to master script. I have used scripts mentioned below. ./ echo $fileExist echo "The script is called"... (2 Replies)
Discussion started by: Raj Roy
2 Replies

5. Shell Programming and Scripting

Script will keep checking running status of another script and also restart called script at night

I am using blow script :-- #!/bin/bash FIND=$(ps -elf | grep "" | grep -v grep) #check is running or not if then # echo "process found" exit 0; else echo "process not found" exec /home/Ketan_r / 2>&1 & disown -h ... (1 Reply)
Discussion started by: ketanraut
1 Replies

6. Shell Programming and Scripting

Suppressing the terminated message from pkill & killall commands in a bash script

Hi all, I've been pulling my hair out with this problem for 3 days:wall: now without success any help would be massively appreciated. Basically the script is used to shutdown a rails server so a new IP address can be assigned, the shutdown part is taken care of in function_one using the... (2 Replies)
Discussion started by: danmc
2 Replies

7. Shell Programming and Scripting

Verifying killall command usage

killall -KILL rdiff-backup Is it a valid command coz i couldn't find a -KILL option for killall in the man page. (1 Reply)
Discussion started by: proactiveaditya
1 Replies

8. Shell Programming and Scripting

create a shell script that calls another script and and an awk script

Hi guys I have a shell script that executes sql statemets and sends the output to a file.the script takes in parameters executes sql and sends the result to an output file. #!/bin/sh echo " $2 $3 $4 $5 $6 $7 isql -w400 -U$2 -S$5 -P$3 << xxx use $4 go print"**Changes to the table... (0 Replies)
Discussion started by: magikminox
0 Replies

9. Shell Programming and Scripting

using killall command

hi all... I investigate if exists some script so that when unix run an application (in this case backup's), so after of that does run killall command to all users connected, or if it is possible to be put in crontab... I wait for and they help me so I do not have much knowledge in programming....... (2 Replies)
Discussion started by: chanfle
2 Replies

Featured Tech Videos