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

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

Don't use 'kill -9' as anything but an absolute last resort.

Run sudo kill to run kill as sudo.

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-

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

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

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.