My main point is that using perl and grep, (multiple thereof!) is nuts when you can do it all in perl.
Also crazy was using -ef (all processes) when the process of interest was using a known user. So ps -u <user> would be more appropriate.
Doing as much in Perl as possible, for portability, you'd do something like
ps -u <user>| perl -ane 'm/[S]omeDaemon/ && kill "SIGTERM", $F[1]'
-a means autosplit into fields, $F[0], F[1], etc so the pid is $F[1].See `perldoc -f kill` for the Perl function kill.
You can also do the `ps` from within Perl but I don't think you'd be gaining much in readability or portability.
kill -HUP $(pidof SomeDaemon)
and if it insists on running, I use: sudo kill -9 $(pidof SomeDaemon)
That's it, really. killall -HUP SomeDaemonThere is a killall on Solaris also which is very different but true to its name. You do not want to run it by accident.
yes, and xargs has a particularly useful argument -P that allows to do stuff in parallel and probably deserves more love :P
`pkill -v` is not verbose mode!
Remember pkill is next to pgrep...
pgrep -l 'reg.*ex" | xargs -L1 do-stuff
or just pkill if the idea is just to send a signal.
To gather particular process metrics, ps can be invoked with process ids (-p), with full control of its output (-o), grep is rarely needed.
do_something_with_pids $(ps -C SomeDaemon ho pid)
Though it's GNU procps.Get-Process | Where-Object { $_.ProcessName -eq 'SomeDaemon' } | Stop-Process
Or at the command line:
ps | ? { $_.ProcessName -eq 'SomeDaemon' } | kill