[Toybox] service
Isaac Dunham
ibid.ag at gmail.com
Sun Jan 4 18:23:14 PST 2015
On Sun, Jan 04, 2015 at 05:57:16PM -0600, Rob Landley wrote:
> On 01/02/2015 12:57 PM, Isaac Dunham wrote:
> > However, having the tools required for init scripts done in C is
> > a significant improvement; killproc,
>
> I need a kill -r that takes out all the descendant processes. It's on
> the todo list...
>
> > pidofproc,
>
> What would "pidofproc" do that toys/lsb/pidof.c doesn't?
>
pidofproc [-p PIDFILE] /path/to/daemon
looks for a pidfile (either PIDFILE or /var/run/daemon.pid),
reads the first line, if that line contains one or more numbers
separated by spaces, use them,
check that they are running, print any applicable pids,
and return 0 "if the program is running" (note the ambiguity about
what that means if multiple pids are found on line 1 of the pidfile!)
To check if it is still running, they imply that one could compare
/path/to/daemon to the start of /proc/$PID/cmdline or to /proc/$PID/exe.
If -p PIDFILE is not specified, you can add any way of searching for
additional pids you wish.
killproc looks like it was meant to be implemented thus:
killproc(){
for PID in `pidofproc "$1"`
do kill $PID $2 # note: $2 is optional
done
if [ -n "$2" ]
then
pidofproc >/dev/null || return 0
return 1
else
pidofproc >/dev/null
return $?
fi
}
> > etc. should not be
> > done in shell (as many init scripts do); they could probably be
> > implemented along with pkill/killall/... and pidof.
> >
All of this is 20.8 in the generic LSB Core specification:
http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptfunc.html
HTH,
Isaac Dunham
1420424594.0
More information about the Toybox
mailing list