Kill multiple processes ran by root


 
Thread Tools Search this Thread
Operating Systems AIX Kill multiple processes ran by root
# 1  
Old 10-20-2017
Kill multiple processes ran by root

Hi all,

I have about 5-6 daemons specific to my application running in the background. I am trying to write a script to stop them. Usually, I run them as a non-root ID, which is fine. But for some reason the client insists on using root.

I do have sudo.

I just tried something like this

Code:
sudo ps ax|grep deamon|awk '{print $1}'|xargs kill -9

kill: 15663166: 0509-013 Permission denied.

kill: 16711728: 0509-013 Permission denied.

kill: 16974010: 0509-013 Permission denied.

kill: 17301670: 0509-013 Permission denied.

kill: 18153676: 0509-013 Permission denied.

kill: 21102690: 0509-013 Permission denied.

kill: 21627104: 0509-013 Permission denied.

kill: 22937744: 0509-013 Permission denied.

kill: 23134276: 0509-013 Permission denied.

kill: 25231382: 0509-015 The specified process does not exist.

This is AIX by the way
# 2  
Old 10-20-2017
Don't use 'kill -9' as anything but an absolute last resort.

Run sudo kill to run kill as sudo.
# 3  
Old 10-20-2017
By 'client', do you mean the person/company paying you or client software?

If it's the former, tell them that they will not be supported, or perhaps get them to run the stop script as root.

If it is client software, then presumably somewhere there is a root-owned & SUID executable somewhere that is called in the start-up. Find that and take away the SUID.




Does that get you any closer?



Robin
# 4  
Old 10-20-2017
Quote:
Originally Posted by rbatte1
By 'client', do you mean the person/company paying you or client software?

If it's the former, tell them that they will not be supported, or perhaps get them to run the stop script as root.

If it is client software, then presumably somewhere there is a root-owned & SUID executable somewhere that is called in the start-up. Find that and take away the SUID.




Does that get you any closer?



Robin
Client as in my company. Who is running the daemon as non root when its not really needed. I've seen several implementations of this product but never seen the daemon running as root.

Heres my end result-

Code:
ps -ef | grep [p]rogram | awk '{print $2}' | xargs sudo kill

# 5  
Old 10-21-2017
The [ ] are special in shell and need to be escaped.
Say you have a file program in your current directory, then the shell replaces [p]rogram by the matching program, and the grep can find its own arguments in the ps args.
Safe is grep "[p]rogram". (It's a good habit to always put the grep argument in quotes!)
Another problem is that xargs runs the kill without arguments if nothing matches.
Suggestion
Code:
pids=$(ps -ef | awk '/[p]rogram/ {print $2}')
[ -n "$pids" ] && sudo kill $pids

Letting awk do the grep is not only more efficient, it also provides means to further add conditions for certain columns.

Last edited by MadeInGermany; 10-21-2017 at 05:21 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

find the no of processes that ran 2 hours before or earlier

Is there a way to find out the total no of processes that were running ? - 2 or 3 hours before - list those no of processes (3 Replies)
Discussion started by: jansat
3 Replies

2. Shell Programming and Scripting

kill multiple processes by name

Want to kill multiple processes by name. for the example below, I want to kill all 'proxy-stagerd_copy' processes. I tried this but didn't work: >> ps -ef|grep proxy_copy root 991 986 0 14:45:34 ? 0:04 proxy-stagerd root 1003 991 0 14:45:49 ? 0:01... (2 Replies)
Discussion started by: catalinawinemxr
2 Replies

3. Shell Programming and Scripting

kill all user processes

Hi there, i've been searching all over and i thought i had understood the way i should go to kill all the processes related to a user. But i'm getting more confused then i was. By lunch time i have to make a database backup, and for that all the users shoul logout. The problem is that many users... (4 Replies)
Discussion started by: vascobrito
4 Replies

4. Shell Programming and Scripting

Kill processes

for i in 'ps -f | grep textedit' do kill $i done I wrote this but it wont work. I am trying to find processes and kill them. Any help would be welcome. (1 Reply)
Discussion started by: hawaiifiver
1 Replies

5. Solaris

kill the processes seen under ptree

Hi, How to kill the processes running under ptree ? I am noticing lot of processes running under ptree with ssh ? I tried to kill with -9 option which is not working ? Thanks, Radhika. (2 Replies)
Discussion started by: radhirk
2 Replies

6. Solaris

kill processes

how to kill the processes of aperticular user? because i have nearly 25000 process are there for perticular user. i need to kill. Please provide the information? Regards, Rajesh (3 Replies)
Discussion started by: pmrajesh21
3 Replies

7. UNIX for Dummies Questions & Answers

Kill several processes at a time

Hello, ps -C a* returns the list of the process I need to kill. but ps -C a* -o pid | kill does not work and I can't get the syntax right. Thanks for any help (4 Replies)
Discussion started by: JCR
4 Replies

8. Shell Programming and Scripting

kill all processes

i have a very short file that has in it a line for a find command. now, when i run this script and I kill the script later, using the ps -ef | grep scriptname. i noticed kill -9 kills the script itself but does not kill the internal find command that it gave birth to. say theres a file... (0 Replies)
Discussion started by: Terrible
0 Replies

9. Filesystems, Disks and Memory

Ran out of space on /dev/root partition

hi, I have a SCO unix server which has a 36gb hard drive, but the IT company who supplied it assigned 1gb to /dev/root, 15mb to /dev/boot and 33gb to /dev/u. The /dev/root partition is now full, is there a way I can use the 33gb assigned to /dev/u without loosing any data, preferably... (2 Replies)
Discussion started by: Martyn
2 Replies

10. Programming

C program to kill root processes

Hello, First let me start by saying I have searched the forum and read all the SUID stuff but it is not in the neighborhood I am looking for. Here is the problem. We want to grant a non super-user permission to kill root processes but only if the process matches certain criteria. ... (8 Replies)
Discussion started by: TioTony
8 Replies
Login or Register to Ask a Question