2 ms·
As per other users, you can use pkill but it's not entirely portable in meaning between OSs. This software had to run on just about every possible Unix out the
by emmelaich 9y ago
As per other users, you can use pkill but it's not entirely portable in meaning between OSs. This software had to run on just about every possible Unix out there. Solaris, HP-UX, AIX, many others ...
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.
- OskarS 9y agoIf it's something you need to do on a semi-regular basis, using a pidfile seems to me to be the best solution. Instead of trying to be clever about pipelines, just write the pid(s) to a file and use that.